SHARE
TWEET

Untitled

a guest Jun 26th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. numpy=1.14
  2.  pandas=1.4
  3.  django=1.6
  4.  flask=1.4
  5.      
  6. import sys
  7.  import re
  8.  program_name = sys.argv[0]
  9.  arguments = sys.argv[1:]
  10.  print (arguments[0])
  11.  print (arguments[1])
  12.  with open('requirement.txt ', 'r') as fr:
  13.      data = fr.readlines()
  14.      with open('requirement.txt ', 'a') as fw:
  15.      fw.write(....)
  16.      
  17. numpy=1.14
  18.  pandas=1.4
  19.  django=2.1
  20.  flask=2.0
  21.      
  22. import re
  23. import sys
  24.  
  25. arguments = dict(i.split("=") for i in sys.argv[1:])   #CMD line Arguments.
  26. with open('requirement.txt', 'r') as fr:         #Read content
  27.     data = fr.read()
  28.  
  29. for k, v in arguments.items():
  30.     data = re.sub(r"{}=(.*)".format(k), "{}={}".format(k,v), data)   #Update content
  31.  
  32. with open(filename, 'w') as fr:              #Write back data.
  33.     fr.write(data)
  34.      
  35. numpy=1.14
  36. pandas=1.4
  37. django=1.6
  38. flask=1.4
  39. django=2.1
  40. flask=2.0
  41.      
  42. fr=open('requirement.txt ', 'r')
  43. L=fr.read().split("n") #Better than .readlines(), since it removes 'n'
  44. fr.close() #Very important, since you're going to write back into it.
  45. D=dict()
  46. for e in L:
  47.     E=e.split("=")
  48.     if len(E)<2:
  49.         continue
  50.     D[E[0]]=E[1]
  51.      
  52. D[arguments[0]]=arguments
  53.      
  54. result="n".join([e+"="+D[e] for e in D])
  55. fw=open('requirement.txt ', 'a')
  56. fw.write(result)
  57. fw.close()
  58.      
  59. import sys
  60.  
  61. requirements = {}
  62.  
  63. # Save a list of requirements
  64. with open('requirement.txt', 'r') as file:
  65.   for line in file:
  66.     line = line.strip("n").split("=")
  67.     requirements[line[0]] = line[1]
  68.  
  69. # Change requirements values
  70. for command in sys.argv[1:]:
  71.   command = command.split("=")
  72.   requirements[command[0]] = command[1]
  73.  
  74. # Write requirements back to file
  75. with open('requirement.txt', 'w') as file:
  76.   for r, v in requirements.items():
  77.     line = "{}={}n".format(r, v)
  78.     file.write(line)
  79.      
  80. import sys
  81. import fileinput
  82.  
  83. program_name = sys.argv[0]
  84. args = sys.argv[1:]
  85.  
  86. if not args:    # ensuring replacement items were passed
  87.     sys.exit('No items to replace')
  88.  
  89. args_dict = dict(arg.split('=') for arg in args)
  90. keys_tuple = tuple(args_dict.keys())
  91.  
  92. for line in fileinput.input(files='requirements.txt', inplace=True):
  93.     if line.startswith(keys_tuple):
  94.         name, version = line.split('=')
  95.         line = line.replace(version, args_dict[name])
  96.     print(line.strip())
  97.      
  98. numpy=1.14
  99. pandas=1.4
  100. django=2.1
  101. flask=2.0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top