Python oddity in Raspian

Wildbill

Ars Praefectus
3,327
Subscriptor++
I vary rarely use Python and I don't much like it, but sometimes it's handy because someone else has done 90% of what I need, particularly where Raspian is concerned.

So by this means, I have a Python3 script that's been running every fifteen minutes for literally years. It uses sleep() without a time. prefix and until yesterday, all that was needed was
Code:
import time

Yesterday I ran an unsupervised apt-get update & upgrade and apparently now I need
Code:
import sleep from time
or I get something like
Code:
 name error: name 'sleep' is not defined
Has some default Python setting been tightened up in my distro? Searching, I see that many people have had similar issues, but not recently.
 

agifford

Ars Tribunus Militum
2,142
You should always have had to do "from time import sleep" or called it as "time.sleep()" if you had just done an "import time", thats the way python modules/imports work.

My only guess is if you had a "from otherpackage import *" and they were accidentally including sleep in their namespace, you would have been getting it that way, instead of from the time module, and they fixed that on an update.
 

agifford

Ars Tribunus Militum
2,142
the function dir() will list what is in the current namespace. (plus __builtins__, which you may need to dir(__builtins__) in case that was getting modified somehow).

if you were able to get back to your previous state, you could print out the results of the dir() function in different places (before & after imports) to track down where the sleep was getting into your namespace. i don't know that its much help now.

https://docs.python.org/3/library/functions.html#dir
 

Wildbill

Ars Praefectus
3,327
Subscriptor++
Python stabbed me in the back again. My script has stopped working after running raspian upgrades. Curiously, it works if I run it from the command line, but not from cron. Logs show something about creating SSL connection to host to use sSMTP and sending mail - none of which my script requests.

So I gave up and wrote the damn thing in C. Problem solved. F U Python :p