Aw: Re: stuck on time
> Sorry, I should have said just the line, and it didn't return anything. OK, a bit strange, but then that might be due to Thonny. > Is Thonny an interpreter then. It sort of is, or at least it runs one. We'd like to take that out of the equation. I meant to run *just* an interpreter, namely, the interactive shell built into Python itself. IOW, run just "python" (or python3) on a command line and a shell should open in which you can run the line in question. (remember to define "time" appropriately) Karsten -- https://mail.python.org/mailman/listinfo/python-list
python 2 to 3 converter
wouldn't it make more sense to just go back and fix the converter program than to have to manually convert all this python2 code? how many small test bits of code from PyPI could be used as templates for patterns to search for that can then be automatically converted and the test rerun? thousands, millions? i bet it isn't a small amount of code that could be done and save everyone a large amount of time. having a large code repository would be useful for such things, but also i think it would be a very good idea for people who make changes to their code which obsolete features or deprecations or whatever you want to call them that they also need to formally describe the transformations needed and supply a conversion script for the code so that there would always be a potential path forwards where some portion of the changes can be done automatically. the thing is that having such a large code repository means you can also index it for code fragments and see which are the most frequently used and then focus on getting those fixes back into the automatic translator program and then keep iterating through as updates are applied and automatic tests succeed. this would be a heck of a lot of fun. songbird -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 8/12/19 9:18 PM, Karsten Hilbert wrote: Sorry, I should have said just the line, and it didn't return anything. OK, a bit strange, but then that might be due to Thonny. Is Thonny an interpreter then. It sort of is, or at least it runs one. We'd like to take that out of the equation. I meant to run *just* an interpreter, namely, the interactive shell built into Python itself. IOW, run just "python" (or python3) on a command line and a shell should open in which you can run the line in question. (remember to define "time" appropriately) From response just posted to Python-Tutor list: WebRefs: https://pythonprogramminglanguage.com/repl/ https://codewith.mu/en/tutorials/1.0/repl -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 08/12/2019 08:18, Karsten Hilbert wrote:
Sorry, I should have said just the line, and it didn't return anything.
OK, a bit strange, but then that might be due to Thonny.
Is Thonny an interpreter then.
It sort of is, or at least it runs one. We'd like to take
that out of the equation. I meant to run *just* an interpreter, namely,
the interactive shell built into Python itself.
IOW, run just "python" (or python3) on a command line and a shell
should open in which you can run the line in question.
(remember to define "time" appropriately)
Karsten
In an interactive interpreter:
def print_time():
current_time = time.strftime("%I:%M")
returns nothing.
I don't know if that is the correct way as I am just using the code from
the project I am trying to do
--
https://mail.python.org/mailman/listinfo/python-list
Re: stuck on time
On 08/12/2019 04:37, Dennis Lee Bieber wrote:
On Sat, 7 Dec 2019 20:38:20 +, RobH declaimed the
following:
What program has or is an interactive interpreter, if it's not Thonny
Thonny is an IDE... It might expose access to the Python interpreter
(I've only loaded it once -- I tend to write my code using PythonWin [on
Windows10] and FTP it to the target machine). However...
The basic interactive interpreter is reached by starting Python in a
command shell with no source file specified, as in...
wulfraed@ElusiveUnicorn:~$ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
print("This is the interactive interpreter state")
This is the interactive interpreter state
It is difficult to offer aid when you fail to provide complete examples
of the problem.
def display_time():
# Collect current time and date
if(time_format):
current_time = time.strftime("%I:%M")<<< stays at this line
else:
current_time = time.strftime("%H:%M")
current_date = time.strftime("%d/%m/%Y")
# Clear image buffer by drawing a black filled box
draw.rectangle((0,0,width,height), outline=0, fill=0
Fails to provide anything usable: What is "time_format"? Where is it
defined. Where/What are "width" and "height"? Also, that line is incomplete
-- you should be getting a syntax error on "draw.rectangle" if that is all
you really have.
Nothing in the provided snippet outputs anything to do with time/date.
I could not provide examples of the problem because there were none, as
the display was showing just the current time and nothing else happened
as I expected it to do according to the code.
The snippet of code you see is the code taken from the code of the said
project I linked to in my first post.
I only provided or posted it to show what should happen next after the
time was displayed.
--
https://mail.python.org/mailman/listinfo/python-list
Re: python 2 to 3 converter
On Sun, Dec 8, 2019 at 7:36 PM songbird wrote: > this would be a heck of a lot of fun. Then go ahead and do it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Aw: Re: Re: stuck on time
> In an interactive interpreter:
>
> def print_time():
> current_time = time.strftime("%I:%M")
>
> returns nothing.
That should be correct.
What happens if you then do
print_time()
inside the interpreter ?
Karsten
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: stuck on time
On 08/12/2019 10:39, Karsten Hilbert wrote:
In an interactive interpreter:
def print_time():
current_time = time.strftime("%I:%M")
returns nothing.
That should be correct.
What happens if you then do
print_time()
inside the interpreter ?
Karsten
print_time()
on it's own returns NameError: name 'print_time' is not defined
def print_time();
print_time()
returns nothing
--
https://mail.python.org/mailman/listinfo/python-list
Aw: Re: Re: Re: stuck on time
> >> In an interactive interpreter:
> >>
> >> def print_time():
> >> current_time = time.strftime("%I:%M")
> >
> > What happens if you then do
> >
> > print_time()
> >
>
> print_time()
> on it's own returns NameError: name 'print_time' is not defined
Notice the "then" above ?
More precisely: directly one after the other without leaving the interpreter ...
Karsten
--
https://mail.python.org/mailman/listinfo/python-list
Re: Vim settings for Python (was: tab replace to space 4)
On 2019-12-07 11:59:31 -0800, Bill Campbell wrote: > On Sat, Dec 07, 2019, Peter J. Holzer wrote: > >As an aside, to prevent vim from inserting tabs in the first place, set > >expandtab > >sw=4 > >and maybe also > >ts=4 > > Inserting a comment in the file like this makes thing easy. > > # vim: expandtab sw=4 ts=4 nows wm=0 Yeah, I do that a lot. hp -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | [email protected] |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
On 08/12/2019 13:06, Karsten Hilbert wrote:
In an interactive interpreter:
def print_time():
current_time = time.strftime("%I:%M")
What happens if you then do
print_time()
print_time()
on it's own returns NameError: name 'print_time' is not defined
Notice the "then" above ?
More precisely: directly one after the other without leaving the interpreter ...
Karsten
I'm not sure what you mean.
Like this?
>>>print_time()
Traceback (most recent call last)
File "stdin>", line 1, in
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth excedded.
Running the code in a shell , it is displaying the time and now also the
date .
Nothing else tho', as in no rectangle drawn
--
https://mail.python.org/mailman/listinfo/python-list
Aw: Re: Re: Re: Re: stuck on time
> Like this? > >>>print_time() > Traceback (most recent call last) > File "stdin>", line 1, in > File "stdin>", line 2, in print_time > File "stdin>", line 2, in print_time > File "stdin>", line 2, in print_time > [Previous line repeated 996 more times] > RecursionError: maximum recursion depth excedded. Sort of, yes, but since you meanwhile redeclared the function: def print_time(): print_time() to be recursive and then you ran that recursive function it recursed until it ran out of resources. However, > Running the code in a shell , it is displaying the time and now also the > date . That would prove that the code itself is not the reason why it hangs where you think it hangs. I suggest sprinkling print statements about the initial code and see what it prints to the console to find out where (and whether) it actually hangs. Karsten -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
RobH wrote:
On 08/12/2019 13:06, Karsten Hilbert wrote:
In an interactive interpreter:
def print_time():
current_time = time.strftime("%I:%M")
What happens if you then do
print_time()
print_time()
on it's own returns NameError: name 'print_time' is not defined
Notice the "then" above ?
More precisely: directly one after the other without leaving the
interpreter ...
Karsten
I'm not sure what you mean.
Like this?
>>>print_time()
Traceback (most recent call last)
File "stdin>", line 1, in
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth excedded.
Running the code in a shell , it is displaying the time and now also the
date .
Nothing else tho', as in no rectangle drawn
Well... Maybe it's time to admit, Rob, that programming is not
your thing.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
On Mon, Dec 9, 2019 at 1:36 AM Python wrote:
>
> RobH wrote:
> > On 08/12/2019 13:06, Karsten Hilbert wrote:
> > In an interactive interpreter:
> >
> > def print_time():
> > current_time = time.strftime("%I:%M")
>
> What happens if you then do
>
> print_time()
>
> >>>
> >>> print_time()
> >>> on it's own returns NameError: name 'print_time' is not defined
> >>
> >> Notice the "then" above ?
> >>
> >> More precisely: directly one after the other without leaving the
> >> interpreter ...
> >>
> >> Karsten
> >>
> > I'm not sure what you mean.
> >
> > Like this?
> > >>>print_time()
> > Traceback (most recent call last)
> > File "stdin>", line 1, in
> > File "stdin>", line 2, in print_time
> > File "stdin>", line 2, in print_time
> > File "stdin>", line 2, in print_time
> > [Previous line repeated 996 more times]
> > RecursionError: maximum recursion depth excedded.
> >
> > Running the code in a shell , it is displaying the time and now also the
> > date .
> > Nothing else tho', as in no rectangle drawn
>
> Well... Maybe it's time to admit, Rob, that programming is not
> your thing.
>
That's rude and uncalled for, and since you're hiding behind
anonymity, you're painting your newsgroup server in a bad light (it's
proxad.net if anyone's curious).
Rob, I recommend working through a Python tutorial. There are some
subtleties to what you're doing that would best be discovered through
experimentation, and a good tutorial will help with that. Try this
one:
https://docs.python.org/3/tutorial/index.html
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
On 08/12/2019 14:39, Chris Angelico wrote:
On Mon, Dec 9, 2019 at 1:36 AM Python wrote:
RobH wrote:
On 08/12/2019 13:06, Karsten Hilbert wrote:
In an interactive interpreter:
def print_time():
current_time = time.strftime("%I:%M")
What happens if you then do
print_time()
print_time()
on it's own returns NameError: name 'print_time' is not defined
Notice the "then" above ?
More precisely: directly one after the other without leaving the
interpreter ...
Karsten
I'm not sure what you mean.
Like this?
>>>print_time()
Traceback (most recent call last)
File "stdin>", line 1, in
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
File "stdin>", line 2, in print_time
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth excedded.
Running the code in a shell , it is displaying the time and now also the
date .
Nothing else tho', as in no rectangle drawn
Well... Maybe it's time to admit, Rob, that programming is not
your thing.
That's rude and uncalled for, and since you're hiding behind
anonymity, you're painting your newsgroup server in a bad light (it's
proxad.net if anyone's curious).
Rob, I recommend working through a Python tutorial. There are some
subtleties to what you're doing that would best be discovered through
experimentation, and a good tutorial will help with that. Try this
one:
https://docs.python.org/3/tutorial/index.html
ChrisA
Thanks, but I am only using the code which someone else has written, and
apparently it works ok for them and others but not for me.
I only came here to find out why, and that is why I posted the link to
the code, which I thought would be helpful to anyone who wishes to reply.
I know I am not a python programmer, although have done some VB
programming years ago.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
On Mon, Dec 9, 2019 at 1:56 AM RobH wrote: > Thanks, but I am only using the code which someone else has written, and > apparently it works ok for them and others but not for me. > > I only came here to find out why, and that is why I posted the link to > the code, which I thought would be helpful to anyone who wishes to reply. > > I know I am not a python programmer, although have done some VB > programming years ago. "Not a Python programmer" is something that can easily be changed :) Python's an easy language to pick up, and since you have some programming experience already, even easier. If you have half an hour - maybe a whole hour to be on the safe side - just work your way through the tutorial and get that "ah ha" moment as you figure out what's actually happening here. You'll unlock a ton of coolness! :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: Re: stuck on time
On 08/12/2019 14:26, Karsten Hilbert wrote: Like this? >>>print_time() Traceback (most recent call last) File "stdin>", line 1, in File "stdin>", line 2, in print_time File "stdin>", line 2, in print_time File "stdin>", line 2, in print_time [Previous line repeated 996 more times] RecursionError: maximum recursion depth excedded. Sort of, yes, but since you meanwhile redeclared the function: def print_time(): print_time() to be recursive and then you ran that recursive function it recursed until it ran out of resources. However, Running the code in a shell , it is displaying the time and now also the date . That would prove that the code itself is not the reason why it hangs where you think it hangs. I suggest sprinkling print statements about the initial code and see what it prints to the console to find out where (and whether) it actually hangs. Karsten Ok, when I do: >>>def print_time(): print_time() It hangs. the code I linked to apparently works for the author and also for some others, but not for me. Admittedly they are using the Minecraftia.ttf font which gives me the IOError which posted about above this one. I am presently using the NotoSerif-Regular.ttf font, and I only think that that is why nothing else happens. Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: stuck on time
On 07/12/2019 17:48, RobH wrote:
> I am trying to do this project on a pi zero:
>
> http://frederickvandenbosch.be/?p=1365
>
> After overcoming a few errors, I now have the display working and the
> start of the code showing on the display, that being the time.
>
> It doesn't move on to the next part of the code ie, no rectangle drawn
> def display_time():
> # Collect current time and date
> if(time_format):
> current_time = time.strftime("%I:%M")<<< stays at this line
> else:
> current_time = time.strftime("%H:%M")
>
> current_date = time.strftime("%d/%m/%Y")
>
> # Clear image buffer by drawing a black filled box
> draw.rectangle((0,0,width,height), outline=0, fill=0
>
> In the original code you can see that the author used the
> Minecraftia.ttf font, but I had to download the Minecraftia-Regular.ttf
> font. The link the author gave took me to that.
>
> The Minecraft-Regular.ttf font produced errors when the code was run,
> saying at the end of the error that it cannot open resource.
>
> I then used the NotoSerif-Regular.ttf font which let the code start
> without error, but as above it is stuck at the time.
One thing you certainly need to do is add a closing brace to the last line.
Duncan
--
https://mail.python.org/mailman/listinfo/python-list
Python3 - How do I import a class from another file
Hello all, Using Python3 I would like to import a specific class from another file (in the same folder), and have trouble doing so. "from file import function" works, but fails when I try to do the same with a class. "import file x = file.class" works, but also executes commands that are in the root of the file. And ofcourse loads all of the file, not just the class that I'm after ... In other words, what is the syntaxt I should use ? Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Re: Re: stuck on time
On 12/08/2019 06:32 AM, Python wrote: Well... Maybe it's time to admit, Rob, that programming is not your thing. Rob, my apologies. Whoever this person is, they are not "Python", and their behavior will not be tolerated. "Python", if you don't want to help then remain silent. If you don't want to be frustrated, stop reading the thread. Rude behavior will not be tolerated. Consider this your one warning. -- ~Ethan~ Python List Moderator -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
On Mon, Dec 9, 2019 at 3:31 AM R.Wieser wrote: > > Hello all, > > Using Python3 I would like to import a specific class from another file (in > the same folder), and have trouble doing so. > > "from file import function" works, but fails when I try to do the same with > a class. > > "import file > x = file.class" > > works, but also executes commands that are in the root of the file. And > ofcourse loads all of the file, not just the class that I'm after ... > > In other words, what is the syntaxt I should use ? > Are you sure there's a difference between classes and functions here? Try "from file import function" and see if it runs commands at the root of the file. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
R.Wieser wrote:
Hello all,
Using Python3 I would like to import a specific class from another file (in
the same folder), and have trouble doing so.
"from file import function" works, but fails when I try to do the same with
a class.
"import file
x = file.class"
works, but also executes commands that are in the root of the file. And
ofcourse loads all of the file, not just the class that I'm after ...
from the_file import ClassName
should work. I guess that your class name is not "class" right?
Note that in all cases when you import a module (either by
import the_file or from the_file importe whatever) you actually
import ALL of it (even if you don't see ALL names your name
space). If you do not want part of a module to be executed when
it is imported (any ways) but only when the file is executed
as a script (i.e. python3 the_file.py or ./the_file.py) then
you can test the name __name__ : it is a string "__main__"
when it is executed and the module name when imported :
if __name__ == '__main__':
# not run when imported
print("Hello world!")
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
R.Wieser wrote:
> Hello all,
>
> Using Python3 I would like to import a specific class from another file
> (in the same folder), and have trouble doing so.
>
> "from file import function" works, but fails when I try to do the same
> with a class.
Are you sure? It should behave the same for any name in the module.
> "import file
> x = file.class"
>
> works, but also executes commands that are in the root of the file. And
> ofcourse loads all of the file, not just the class that I'm after ...
>
> In other words, what is the syntaxt I should use ?
The body of a module that is imported is always executed -- that's how the
classes and functions (and everything else) in the module are created.
It's all or nothing, you cannot cherry-pick specific classes or functions.
You can however protect part of the code with
'if __name__ == "__main__": ...':
print("this will always be executed")
if __name__ == "__main__":
print("this will only be executed when you run")
print("the module directly as a script")
--
https://mail.python.org/mailman/listinfo/python-list
Re: python 2 to 3 converter
Chris Angelico wrote: > On Sun, Dec 8, 2019 at 7:36 PM songbird wrote: >> this would be a heck of a lot of fun. > > Then go ahead and do it. i know you're just being flip here and that's fine with me. that said, i'd love to! how big is PyPI? (huge) will it fit on an SSD? (no) my local machine and pipeline isn't big enough to crunch it (too bad). etc. i'm going to have fun here so you can ignore this if you'd like. my name for the new archive is called OctoPyPIE. :) uploads to OPPIE are parsed from the start to be python3 compatible only. if it is not compatible then the code is quarantined with a message which says "fix it and try again, we no longer accept incompatible code." the quarantined python2 code will be used for background processing (to see what is most broken) but it is never distributed further. it is just indexed, dependencies checked, noting which ones are most frequently used and that information kept to help focus the broader effort of conversion. i think we should call the quarantine area ISENGUARD and the programs for chewing it up called ENT. code that eventually may get a fixer so that it could be promoted back to OPPIE without any manual intervention would be done by ELROND. code which is impossible to ever be manually converted would be left and perhaps would eventually end up in MORDOR after being transported by the RINGWRAITH. dev null is of course MTDOOM. those who come to the table of OPPIE only eat the freshest pie. HOBBITS like only the best. thus is finished the 2nd AGE. songbird -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
Chris, > Are you sure there's a difference between classes and functions here? Yes, quite sure. If not my attempt to load a class he same way as a function would have worked. Which it doesn't. > Try "from file import function" and see if it runs commands at > the root of the file. What function ? The imported file doesn't contain any. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
Python,
> from the_file import ClassName
>
> should work. I guess that your class name is not "class" right?
You guessed that right. :-) Not a good idea to pick confusing names like
that, especially when you do something the first time.
> Note that in all cases when you import a module (either by import the_file
> or from the_file importe whatever) you actually import ALL of it
So much for my assumption only the class itself would be loaded - and a
wrench into my idea to have a number of classes in a "library" file.
And it turns out its also the cause of my problem: The displayed error told
me that it could not import the class from the file, but when I block-quoted
the testcode (instanciating the class, calling it and deleting the instance
afterwards) it all worked as it should. No idea why though.
> if __name__ == '__main__':
> # not run when imported
> print("Hello world!")
Thanks for that. It means I do not have to block-quote the testcode every
time - which I'm certain I will forget now-and-again ...
Update: While testing a bit more it turned out that, in the testcode, my
creating an instance with the same name as the class is to blame (who again
said that it isn't a good idea to use confusing names ?). The moment I
changed the name of the instance everything works as expected.
Question: what is, in python, the convention in naming classes ? Pre- or
postfix it with "class" ? Something else ?
Regards,
Rudy Wieser
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
Peter, >> "from file import function" works, but fails when I try to do the same >> with a class. > > Are you sure? It should behave the same for any name in the module. I am. At least, that is what the error said: "cannot import 'classname' from 'filename' " But as it turns out the problem is not the importing, but that my importing of the class also caused my testcode (instanciating the class, calling it and deleting the instance afterwards) to run. ... in which I created an instance with the same name as the class. Changing the instances name made the error go away (probably something to do with the "del instance" in the testcode). > It's all or nothing, you cannot cherry-pick specific classes or functions. Shucks. > You can however protect part of the code with > 'if __name__ == "__main__": ...': Thanks. (Python" also mentioned the above two). Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 08/12/2019 16:49, Dennis Lee Bieber wrote:
On Sun, 8 Dec 2019 09:44:54 +, RobH declaimed the
following:
def print_time():
current_time = time.strftime("%I:%M")
returns nothing.
So what did you expect it to do?
All that does is define a function (binding the name "print_time" to a
compiled function object), and that function itself returns nothing IF
invoked (you haven't invoked it). (Presuming time has been imported, the
function will bind the name "current_time" to a string representation of
the current time... and then throws away "current_time" when the function
falls off the end and returns to the caller.)
I don't know if that is the correct way as I am just using the code from
the project I am trying to do
This is showing a severe lack of understanding in how Python itself
operates, leading me to recommend rereading a Python tutorial book before
attempting to hack into some one else's code.
Err, excuse me, I was not attempting to hack into someone else's code.
As the code is in the public domain, I wanted it to work as is, like it
did for the author, without changing anything.
So why should I now start to learn how python works.
If the code doesn't work for me after a fair trial, I'll move on to
something else.
--
https://mail.python.org/mailman/listinfo/python-list
Regarding problem in python 3.8.0 installation
Sir, My system is windows 7 SP1 32-bit . after installing python in my system,when i try to launch it using command prompt then a message is shown. I am attaching a screenshot of the following. kindly look seriously into my problem and tell me the solution.. thank you -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
Dennis, > Common practice is that the class is capitalized. Instances >are lowercase. Thanks. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
On 12/8/2019 1:29 PM, R.Wieser wrote:
from the_file import ClassName
from somemod import name
has the same effect as
import somemod
name = somemod.name
del somemod
which is to import a particular 'name' linked to a particular python
object into the namespace where the import is executed.
sys.modules['somemod'] will become or continue to be the module
resulting from executing the 'somemod' code.
Note that in all cases when you import a module (either by import the_file
or from the_file importe whatever) you actually import ALL of it
The entire module is executed the first time it is imported.
So much for my assumption only the class itself would be loaded - and a
wrench into my idea to have a number of classes in a "library" file.
Not really. The resulting global objects do not normally take enough
space to worry about on normal modern desktops. It is normal for a
module to only use a subset, possibly just one, of the objects in an
imported module. For instance, itertools has 18 public classes but
almost no importer uses all of them.
if __name__ == '__main__':
# not run when imported
print("Hello world!")
Thanks for that. It means I do not have to block-quote the testcode every
time - which I'm certain I will forget now-and-again ...
Standard for in-file test is
def test():
if __name__ == '__main__':
test()
Question: what is, in python, the convention in naming classes ?
The PEP 8 convention (except for basic builtin data structures like int,
str, list, tuple, set, and dict) is TitleCase. Follow or not as you wish.
Pre- or postfix it with "class" ?
No
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 9/12/19 7:47 AM, RobH wrote:
On 08/12/2019 16:49, Dennis Lee Bieber wrote:
On Sun, 8 Dec 2019 09:44:54 +, RobH declaimed the
following:
def print_time():
current_time = time.strftime("%I:%M")
...
I don't know if that is the correct way as I am just using the code from
the project I am trying to do
This is showing a severe lack of understanding in how Python itself
operates, leading me to recommend rereading a Python tutorial book before
attempting to hack into some one else's code.
+1
(in other words, agreement with others who have suggested that your
knowledge of Python and/or programming, is insufficient to cope with the
project you've set yourself)
Err, excuse me, I was not attempting to hack into someone else's code.
As the code is in the public domain, I wanted it to work as is, like it
did for the author, without changing anything.
Please don't be upset. There are multiple understandings of the words
"hack" and "hacker". Whereas most 'computer people' take the word "hack"
to mean exactly what you are doing (and "crack" to refer to illegal
access or ill-intent); the sad state of journalism (and Hollywood) has
resulted in a confusion of the two.
Within the Python community, the word "hack" is used freely and without
rancour, and includes both the permitted use of someone else's code, as
you describe; and improving said code, as per @wlfraed's detailed
analysis of the code-base's short-comings, a few hours ago.
So why should I now start to learn how python works.
Only you can answer this: is the effort required to bend the code to
your will, worth the pleasure or utility the result will bring?
Alternatively, look at how much time *volunteers* have thought
worth-while investing in helping you! (kudos @Karsten)
There is a safety issue here too. What if the original author had wicked
intent, and the code actually performs to your disadvantage. How would
you know? The only way is to inspect the code - reading it for example.
Following-on from the "hacking" comment, if the original author offered
it to you/the world, and uploaded this code to some public repo(sitory),
(s)he will also be happy for you/others to correct and improve.
Added to the observation that the code is missing parentheses, it would
seem that (this version of) the code would never work. Now that you have
discovered this, the conventions of "open source" are that you will
propose, or better still, supply a fix...
If the code doesn't work for me after a fair trial, I'll move on to
something else.
Frankly, given @wlfraed's extensive analysis of the code, I'd be
wondering about its utility too - but again, your assessment is the only
one that counts.
(If I am confusing two recent list-threads, I apologise)
If you are going to be experimenting with IoT and/or SBCs, the sad
reality is that it is not an area which has had time to 'collect' a body
of mature software. Accordingly, lots of the code made 'available' for
use will be in a fairly rough (or "early") stage. Thus, the greater
*your* skill-set, the more likely will be success - same as for any
hobby/work-project! Also, IIRC you are also short-cutting by using a
Pi-Zero (designed for application and roll-out) rather than a board
designed for experimentation - but I'm guessing, so again, please don't
take offense.
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 12/8/19 11:47 AM, RobH wrote: > Err, excuse me, I was not attempting to hack into someone else's code. > As the code is in the public domain, I wanted it to work as is, like it > did for the author, without changing anything. No worries, you're totally fine. The word "hack" means something different. To hack means to work on, learn, modify, etc. It's a positive word in this context. I was hacking on python code myself yesterday. > So why should I now start to learn how python works. Well if you learn how Python works, then a lot of what you are trying to do will become easier and make more sense. For example, knowing how Python works will tell you why your print_time() function returns nothing (hint, the code you posted does not show a "return" statement, hence the function will not return anything). > If the code doesn't work for me after a fair trial, I'll move on to > something else. I can sense that you are frustrated, and I can also sense frustration on the part of those trying to assist you. I hope you will give it a fair trial as the entire endeavor, and Python in particular, can be really fun once you grasp it! -- https://mail.python.org/mailman/listinfo/python-list
Re: Regarding problem in python 3.8.0 installation
On 12/8/2019 1:08 PM, alok singh wrote: My system is windows 7 SP1 32-bit . after installing python in my system,when i try to launch it using command prompt then a message is shown. I am attaching a screenshot of the following. Screenshots are not allowed. Copy and paste from CommandPrompt. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
RE: ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package
Just registered Thanks Original Message Subject: ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package From: <[1][email protected]> Date: Sun, December 08, 2019 11:14 am To: [2][email protected] Hello Python Team, I am a beginner in Python, been working on class material from Mosh youtube 6 hrs., Mosh 12 hr paid course; Python Cash Course by Eric Matthes … most of the time everything works just fine or a little adjustment for updated versions. I am running Python 3.8.0 In example, Mosh 12 hr course, he did an exercise on sending email from within Python, so here is the code : from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib message = MIMEMultipart() message["from"] = "Bob Hoyer = Python" message["to"] = "[3][email protected]" message["subject"] = "This is a test using Python" message.attach(MIMEText("Body")) # godaddy recommended SMTP_SSL, host name & port # with smtplib.SMTP(host="smtpout.secureserver.net", port=465) as smtp: smtp.ehlo() # godaddy recommended removing ... # smtp.starttls() smtp.login("[4][email protected]", "password") #email login & password blanked out for this msg smtp.send_message(message) print("Sent ...") smtp.close() Here is the error message: Traceback (most recent call last): File "c:\Users\Owner\Desktop\HelloWorld\[5]email.py", line 1, in from email.mime.multipart import MIMEMultipart File "c:\Users\Owner\Desktop\HelloWorld\[6]email.py", line 1, in from email.mime.multipart import MIMEMultipart ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package I have spent some time trying to figure out resolve ... Can you help me with this pistol of a problem … Bob Hoyer References Visible links 1. mailto:[email protected] 2. mailto:[email protected] 3. mailto:[email protected] 4. mailto:[email protected] 5. http://email.py/ 6. http://email.py/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
On 9/12/19 7:29 AM, R.Wieser wrote:
...
Note that in all cases when you import a module (either by import the_file
or from the_file importe whatever) you actually import ALL of it
So much for my assumption only the class itself would be loaded - and a
wrench into my idea to have a number of classes in a "library" file.
There are three separate ideas which may be confusing:
1 we can 'load' a single class from a module, and
2 we can have 'library files' ("modules") which contains more than one
importable-object
3 when a module is imported, parts of it are/may be executed at import-time
...
Update: While testing a bit more it turned out that, in the testcode, my
creating an instance with the same name as the class is to blame (who again
said that it isn't a good idea to use confusing names ?). The moment I
changed the name of the instance everything works as expected.
and then there are the concepts of "scope" and "namespace".
Some of this you will know. (Hopefully) some will be 'new':
import moduleNM
- imports the entire contents of the module and executes what can be.
This means that functions and classes are defined, and any executable
code in the 'mainline', eg print( "Hello World" ); will be run.
- from that time you may then refer to the objects detailed within the
module, eg
a = moduleNM.ClassA()
- note how the module has become part of the program, but occupies a
separate "namespace"
from moduleNM import ClassA
- changes things so that you may now refer to ClassA without mention of
the moduleNM, ie brings the name "ClassA" into the current namespace
- causes confusion if there is already a ClassA in the current namespace!
from moduleNM import ClassA as ClassA2
- also obviates the need to mention moduleNM/adds to the current namespace
- allows use of both ClassA-s - the 'local' ClassA as "ClassA", as well
as providing an alias ("ClassA2") to the ClassA defined in moduleNM
import moduleNM as aliasNM; is also available!
WebRefs:
A comfortably readable expansion of the above:
https://www.digitalocean.com/community/tutorials/how-to-import-modules-in-python-3
Python's view of (import-able) modules:
https://docs.python.org/3/tutorial/modules.html
Other questions answered:
https://docs.python.org/3/faq/programming.html?highlight=import, eg
what-are-the-best-practices-for-using-import-in-a-module
The importlib library which under-pins "import":
https://docs.python.org/3/reference/import.html
The full-fat range of import-possibilities:
https://docs.python.org/3/library/modules.html--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 9/12/19 7:47 am, RobH wrote: I wanted it to work as is, like it did for the author, without changing anything. So why should I now start to learn how python works. There are many, many reasons a piece of code could work in one environment but not another. Figuring out why requires actual understanding, not just copy-pasting. Part of that involves gaining at least a basic knowledge of the language you're using. You can't expect folks here to do all your work for you. We're trying to help, but we can't debug your code and/or system remotely, because we don't know everything about it. We can offer advice, but ultimately you're the one who has to work it out. If you don't think the project is worth that much effort, that's up to you. But you asked for help, and we're doing our best to give it. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: stuck on time
On 9/12/19 7:46 am, Dennis Lee Bieber wrote: Minecraftia appears to be a monospaced font meant to look like the character set of old 8-bit gaming systems from the 80s. From the name, it's probably mean to resemble the font in Minecraft. As used in the game it's not actually monospaced, but it is designed for very low resolution, so it's probably a reasonable choice for use on a small display. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2 to 3 converter
On 8/12/19 9:30 pm, songbird wrote: wouldn't it make more sense to just go back and fix the converter program than to have to manually convert all this python2 code? Anything that isn't already fixed by 2to3 is probably somewhere between very difficult and impossible to fix using an automated process. It sounds like an interesting project, but be aware that it's probably an AI-complete problem. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package
On 2019-12-08 19:13, [email protected] wrote: Just registered Thanks Original Message Subject: ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package From: <[1][email protected]> Date: Sun, December 08, 2019 11:14 am To: [2][email protected] Hello Python Team, I am a beginner in Python, been working on class material from Mosh youtube 6 hrs., Mosh 12 hr paid course; Python Cash Course by Eric Matthes … most of the time everything works just fine or a little adjustment for updated versions. I am running Python 3.8.0 In example, Mosh 12 hr course, he did an exercise on sending email from within Python, so here is the code : from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib message = MIMEMultipart() message["from"] = "Bob Hoyer = Python" message["to"] = "[3][email protected]" message["subject"] = "This is a test using Python" message.attach(MIMEText("Body")) # godaddy recommended SMTP_SSL, host name & port # with smtplib.SMTP(host="smtpout.secureserver.net", port=465) as smtp: smtp.ehlo() # godaddy recommended removing ... # smtp.starttls() smtp.login("[4][email protected]", "password") #email login & password blanked out for this msg smtp.send_message(message) print("Sent ...") smtp.close() Here is the error message: Traceback (most recent call last): File "c:\Users\Owner\Desktop\HelloWorld\[5]email.py", line 1, in from email.mime.multipart import MIMEMultipart File "c:\Users\Owner\Desktop\HelloWorld\[6]email.py", line 1, in from email.mime.multipart import MIMEMultipart ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package I have spent some time trying to figure out resolve ... Can you help me with this pistol of a problem … Bob Hoyer [snip] I notice you have files called "[5]email.py" and "[6]email.py". Do you also have one called "email.py"? If so, then what's happening is that Python is finding that one before the one in the stdlib. -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 2019-12-08 20:34, Michael Torrie wrote: On 12/8/19 11:47 AM, RobH wrote: Err, excuse me, I was not attempting to hack into someone else's code. As the code is in the public domain, I wanted it to work as is, like it did for the author, without changing anything. No worries, you're totally fine. The word "hack" means something different. To hack means to work on, learn, modify, etc. It's a positive word in this context. I was hacking on python code myself yesterday. The word for breaking into a system or program is/was "crack", like in "safe-cracking". In common parlance, however, people have picked up the word "hack" instead, which, as Michael says, means something else. It's a lot like the misuse of the word "theory". [snip] -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package
On 9/12/19 8:13 AM, [email protected] wrote: Just registered Thanks Hi @bob, welcome to the gang... I am a beginner in Python, been working on class material from Mosh ... from email.mime.multipart import MIMEMultipart ... Here is the error message: Traceback (most recent call last): File "c:\Users\Owner\Desktop\HelloWorld\[5]email.py", line 1, in from email.mime.multipart import MIMEMultipart File "c:\Users\Owner\Desktop\HelloWorld\[6]email.py", line 1, in from email.mime.multipart import MIMEMultipart ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package I have spent some time trying to figure out resolve ... Can you help me with this pistol of a problem … ("pistol"? ...he says, manfully-struggling with the temptation to suggest that you "make love not war"...) Let's look at the information given (in the "stack trace": <>> On line 1, the code requests that a module named/addressed as "email.mime.multipart" be located ("found"), and an object ("MIMEMultipart") be imported (etc, etc). So, when executing line 1, Python was unable to find the specified module (let's over-simplify and use the word: "file"). Libraries from the Python Standard Library are not included in the basic "python" download, and have to be added/separately downloaded, when needed. I suspect this is the problem (but may not be)! Sadly, I am not a user of MS-Win, so am loath to try to help much more, for fear of leading you along the wrong track. Herewith some self-study which should put your boots (back) on the ground... WebRefs: installing packages This is more readable: https://protechguides.com/how-to-install-python-library/ This is from 'the book of words': https://packaging.python.org/tutorials/installing-packages/ NB I understand that "pip" is installed on MS-Win as part of python, so you don't need to worry about that/can quickly check. If your course has not taken you through "virtual environments" then feel free to ignore such, for now. -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
It's a lot like the misuse of the word "theory". You mean to say that in theory there is no difference between theory and practice, but in practice there is? -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 - How do I import a class from another file
On 9/12/19 6:28 am, R.Wieser wrote: Are you sure there's a difference between classes and functions here? Yes, quite sure. And we're even more sure that there isn't. :-) Try it with a test module containing a class definition, a function definition and some top-level code that does something noticeable. You'll find that *any* form of import executes all the top-level code. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: stuck on time
On 08/12/2019 22:06, Greg Ewing wrote: On 9/12/19 7:47 am, RobH wrote: I wanted it to work as is, like it did for the author, without changing anything. So why should I now start to learn how python works. There are many, many reasons a piece of code could work in one environment but not another. Figuring out why requires actual understanding, not just copy-pasting. Part of that involves gaining at least a basic knowledge of the language you're using. You can't expect folks here to do all your work for you. We're trying to help, but we can't debug your code and/or system remotely, because we don't know everything about it. We can offer advice, but ultimately you're the one who has to work it out. If you don't think the project is worth that much effort, that's up to you. But you asked for help, and we're doing our best to give it. Yes, fair comment that, and I do appreciate the people who do try to help. Thank you to those. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2 to 3 converter
Greg Ewing於 2019年12月9日星期一 UTC+8上午6時18分32秒寫道: > On 8/12/19 9:30 pm, songbird wrote: > >wouldn't it make more sense to just go back and fix the > > converter program than to have to manually convert all this > > python2 code? > > Anything that isn't already fixed by 2to3 is probably > somewhere between very difficult and impossible to fix > using an automated process. It sounds like an interesting > project, but be aware that it's probably an AI-complete > problem. > > -- > Greg Even string is hard to be handled by the AI:-) Quoted from https://portingguide.readthedocs.io/en/latest/strings.html " ... This means that you need to go through the entire codebase, and decide which value is what type. Unfortunately, this process generally cannot be automated." --Jach -- https://mail.python.org/mailman/listinfo/python-list
Decorator as a class and Descriptor __get__ working? - cookbook, 9.9, pg 349
I did not follow the grok bit.. He's creating a Descriptor within class 'Spam' by doing @Profiled def bar() because Profiled replaces 'bar' with it's instance that contains __get__ which means I have to do s.grok = 20 to trigger it? Which would imply, s.__get__(instance, instance, value) NOT whatever he's done.. ? How is he passing Spam to 'grok'? It should be (self=decorator-instance, Spam- instance-s and value) being passed to __get__ (for those who don't have the book, he's switched to 'grok' instead of 'bar') >>> s = Spam() >>> def grok(self, x): ... pass ... >>> grok.__get__(s, Spam) class Spam: @Profiled def bar(self, x): print(self, x) import types from functools import wraps class Profiled: def __init__(self, func): wraps(func)(self) self.ncalls = 0 def __call__(self, *args, **kwargs): self.ncalls += 1 return self.__wrapped__(*args, **kwargs) def __get__(self, instance, cls): if instance is None: return self else: return types.MethodType(self, instance) -- https://mail.python.org/mailman/listinfo/python-list
