0

I am trying to execute the same program with different arguments by calling :

os.execv(sys.executable, ['python'] + [abs_file_path] + [str(new_arg)])

but when I do that and I get to this line, it attempts to run the file but I get ModuleNotFoundError: No module named 'module name' referred to the imported modules that i have at the top of the file (for example pandas, which of course i have it installed on my machine) .

Is it a known sort of bug? Why cant it find the modules to import?

giulio di zio
  • 171
  • 1
  • 11
  • 1
    What are `abs_file_path` and `new_arg`? – Daniel Walker Jul 02 '20 at 16:13
  • Are you trying to call a python program with different arguments? – Dash Jul 02 '20 at 16:14
  • ```abs_file_path``` is the absolute path of my current file (which i have to execute again). And yes, i have to call the current python program but with different args. – giulio di zio Jul 02 '20 at 16:20
  • Is it possible to import the module into a different script and treat it as a function? – Dash Jul 02 '20 at 16:26
  • What module would you move to a different function? I m not sure i got what you mean... Can you provide a sort of quick sample in the answers? – giulio di zio Jul 02 '20 at 19:23
  • I just added a little example, is that an option for you? – Dash Jul 02 '20 at 19:45
  • Why do you need to call the current python program with different args? – Dash Jul 02 '20 at 20:14
  • I am webscraping a website to collect a massive amount of products and i literally tried them all. After a while my requests get blocked. My latest version is using tbselenium which is basically a selenium-like library that provides a Tor webdriver so that i change IP when i close and reopen the browser. But no metter how long i sleep for after i reopen it i am still getting blocked. But if i shut down the program and re run it i notice it it allows me to scrape several products before getting blocked. So while iterating through the list of products to webscrape i d like to kill the program – giulio di zio Jul 02 '20 at 20:50
  • and run it again with the arg being the index in the list belonging to the product I was previously scraping before getting banned. I know it is a really particular thing but I am really trying them all – giulio di zio Jul 02 '20 at 20:54

1 Answers1

0

Not sure if this is an option for you, but it might be possible to do something like:

from myfile import myfunction

my_args = ['foo', 'bar', 'baz']

for new_arg in my_args:
    myfunction(new_arg)

Dash
  • 1,191
  • 7
  • 19
  • Oh i see what tou mean... Unfortunately this isn't the case (BTW I edited my question cause I think I didn't clear one thing about the error I am getting) – giulio di zio Jul 02 '20 at 20:13