Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save plieningerweb/39e47584337a516f56da105365a2e4c6 to your computer and use it in GitHub Desktop.
Save plieningerweb/39e47584337a516f56da105365a2e4c6 to your computer and use it in GitHub Desktop.
Restart python script itsself (run again).md
@malmeloo
Copy link

@Techtiger255 Because that's not how you concatenate lists in python:

>>> my_list = ['foo', 'bar']

>>> print(['spam', my_list])
['spam', ['foo', 'bar']]

>>> print(['spam'] + my_list)
['spam', 'foo', 'bar']

>>> ['spam', my_list] == ['spam'] + my_list
False

Alternatively, you could do my_list.extend(['spam']), however this modifies my_list and might not be what you want.

@shadowpants18
Copy link

I'm getting connectionRefusedError: [WInError 10061], anyone know why?

@Anandoham
Copy link

Thank you for this!

@andreapramadityaperwiraputra
Copy link

thanks for this information dude! it's working for my project, thanks again.

@dante-nl
Copy link

dante-nl commented Feb 8, 2021

Amazing, thank you!

@dante-nl
Copy link

dante-nl commented Feb 8, 2021

Seems like the input function is broken with it tho...

@YYx00xZZ
Copy link

if you want to run/restart your script with -i its not working

@heyjoeway
Copy link

Wouldn't it make more sense to not hardcode the executable name?

import os, sys
def restart():
    os.execv(sys.executable, [os.path.basename(sys.executable)] + sys.argv)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment