Re: What's the difference between running a script under command box and interpreter?
On 31Oct2019 22:03, Jach Fong wrote: Cameron Simpson於 2019年11月1日星期五 UTC+8下午12時13分45秒寫道: On 31Oct2019 20:44, Jach Fong wrote: >The script test.py is something like this: >---test.py >from pyeds import fsm >... >class Rule_Parse: >def __init__(self): >... >self.current_char = '' >... >def main(input_str): >for c in input_str: >... >rule.current_char = c >... > >if __name__ == '__main__': >input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' >rule = Rule_Parse() >main(input_str) >... > >--- >The test.py can run correctly under command box: >D:\Works\Python\pyeds-master\src>py test.py > >but fails when running under interpreter: >D:\Works\Python\pyeds-master\src>py >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 >Type "help", "copyright", "credits" or "license" for more information. from test import * input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" rule = Rule_Parse() main(input_str) >Traceback (most recent call last): > File "", line 1, in > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main >rule.current_char = c >NameError: name 'rule' is not defined > >I did check the globals using dir() and the 'rule' is there, no doubt. It matters how you checked this. This isn't apparent. [...] Yes, the 'if' body is not executed when I import test.py under interpreter, that's why I manually execute them there. What puzzles me is that the globals() has a 'rule' object in both cases. Why this one doesn't work? I think I have misinterpreted what you've done. The globals are your current module's namespace, and functions defines in a module are bound to that module's namespace. Strip your test.py back. A lot. Try this: def main(): print(rule) Now, let's use that: Python 3.7.4 (default, Sep 28 2019, 13:34:38) [Clang 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> test.main() Traceback (most recent call last): File "", line 1, in File "/Users/cameron/tmp/d1/test.py", line 2, in main print(rule) NameError: name 'rule' is not defined What's happening here? When we call main it tries to print "rule" from its module's globals. The first time you call it that doesn't exist, and we get your error. Setting rule=1 in the interpreter's space doesn't help (the stuff below if from the same session continued from above): >>> rule=1 >>> test.main() Traceback (most recent call last): File "", line 1, in File "/Users/cameron/tmp/d1/test.py", line 2, in main print(rule) NameError: name 'rule' is not defined But if we define rule in the "test" module things improve: >>> test.rule=2 >>> test.main() 2 Importing main from test doesn't change where it looks for its globals: >>> from test import main as my_main >>> my_main() 2 That value (2) is still coming out of the test module. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between running a script under command box and interpreter?
Cameron Simpson於 2019年11月1日星期五 UTC+8下午5時28分42秒寫道: > On 31Oct2019 22:03, Jach Fong wrote: > >Cameron Simpson於 2019年11月1日星期五 UTC+8下午12時13分45秒寫道: > >> On 31Oct2019 20:44, Jach Fong wrote: > >> >The script test.py is something like this: > >> >---test.py > >> >from pyeds import fsm > >> >... > >> >class Rule_Parse: > >> >def __init__(self): > >> >... > >> >self.current_char = '' > >> >... > >> >def main(input_str): > >> >for c in input_str: > >> >... > >> >rule.current_char = c > >> >... > >> > > >> >if __name__ == '__main__': > >> >input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' > >> >rule = Rule_Parse() > >> >main(input_str) > >> >... > >> > > >> >--- > >> >The test.py can run correctly under command box: > >> >D:\Works\Python\pyeds-master\src>py test.py > >> > > >> >but fails when running under interpreter: > >> >D:\Works\Python\pyeds-master\src>py > >> >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 > >> >bit (Intel)] on win32 > >> >Type "help", "copyright", "credits" or "license" for more information. > >> from test import * > >> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" > >> rule = Rule_Parse() > >> main(input_str) > >> >Traceback (most recent call last): > >> > File "", line 1, in > >> > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main > >> >rule.current_char = c > >> >NameError: name 'rule' is not defined > >> > >> > > >> >I did check the globals using dir() and the 'rule' is there, no doubt. > >> > >> It matters how you checked this. This isn't apparent. > [...] > >Yes, the 'if' body is not executed when I import test.py under > >interpreter, that's why I manually execute them there. > >What puzzles me is that the globals() has a 'rule' object in both > >cases. Why this one doesn't work? > > I think I have misinterpreted what you've done. > > The globals are your current module's namespace, and functions defines > in a module are bound to that module's namespace. > > Strip your test.py back. A lot. Try this: > > def main(): > print(rule) > > Now, let's use that: > > Python 3.7.4 (default, Sep 28 2019, 13:34:38) > [Clang 8.0.0 (clang-800.0.42.1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import test > >>> test.main() > Traceback (most recent call last): > File "", line 1, in > File "/Users/cameron/tmp/d1/test.py", line 2, in main > print(rule) > NameError: name 'rule' is not defined > > What's happening here? > > When we call main it tries to print "rule" from its module's globals. > > The first time you call it that doesn't exist, and we get your error. > > Setting rule=1 in the interpreter's space doesn't help (the stuff below > if from the same session continued from above): > > >>> rule=1 > >>> test.main() > Traceback (most recent call last): > File "", line 1, in > File "/Users/cameron/tmp/d1/test.py", line 2, in main > print(rule) > NameError: name 'rule' is not defined > > But if we define rule in the "test" module things improve: > > >>> test.rule=2 > >>> test.main() > 2 > > Importing main from test doesn't change where it looks for its globals: > > >>> from test import main as my_main > >>> my_main() > 2 > > That value (2) is still coming out of the test module. > > Cheers, > Cameron Simpson I didn't noticed that the interpreter has its own globals. Thanks for reminding. --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Fwd: python startup failure problem
-- Forwarded message - From: Tanay Dandekar Date: Thu, Oct 31, 2019 at 10:30 PM Subject: python startup failure problem To: Dear Sir, Please find attached photo of Python failure detail. please solve this problem as soon as possible. thanking you, Regard tanay -- https://mail.python.org/mailman/listinfo/python-list
EuroPython 2020: Venue and location selected
After a work intense RFP over two months with more than 40 venues competing, 18 first round entries, and two rounds of refinements, we are now happy to announce the winner: EuroPython 2020 will be held at the CCD in Dublin, Ireland, from July 20 - 26 2020 We will now start work on the contracts and get the organization going, so that we can all enjoy another edition of EuroPython next year. Help spread the word Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://www.europython-society.org/post/188741002380/europython-2020-venue-and-location-selected Tweet: https://twitter.com/europythons/status/1190227133920100352 Enjoy, -- EuroPython Society https://www.europython-society.org/ -- https://mail.python.org/mailman/listinfo/python-list
Fwd: jupyter not install sucessfully
-- Forwarded message - From: Shubham Tomar Date: Fri, 1 Nov 2019 at 13:58 Subject: jupyter not install sucessfully To: Dear sir, i have installed python and then pip , after that i installed jupyter using pip in command prompt. But jupyter can't start and give " external and internal" error in cmd. I also install Anaconda but it shows Kernel error : DLL load failed - The specified procedure not found etc.I also use pip but didn't work yet. I am using Windows 7 but i was try this in windows 10 and still i faced this error. Kindly please help me. -- https://mail.python.org/mailman/listinfo/python-list
Re: python startup failure problem
On Fri, Nov 1, 2019 at 8:59 AM Tanay Dandekar wrote: > > -- Forwarded message - > From: Tanay Dandekar > Date: Thu, Oct 31, 2019 at 10:30 PM > Subject: python startup failure problem > To: > > > Dear Sir, > > Please find attached photo of Python failure detail. > > please solve this problem as soon as possible. > > thanking you, > > Regard > tanay > -- > https://mail.python.org/mailman/listinfo/python-list Dear Tanay, Some, perhaps most people, might find it rude to assume that people here will solve your problem! This is a mailing list where people will help you solve python problems. You need to do your part as well. Photos, or any attachments are removed before your message is sent to list members. Please copy and paste your traceback from when you run your code, and describe the problems you are having. Also nice is your OS, python version. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: Jupyter Notebook -> PDF with A4 pages?
On Thu, 31 Oct 2019 at 22:08, Martin Schöön wrote: > Den 2019-10-16 skrev Piet van Oostrum : >> Why should that not work? > pip install --user pip broke pip. I have not been able to repair pip I guess that's just the local pip shadowing the system one when you let the command "pip" to be resolved by the shell. , try calling the absolute path /usr/bin/pip . I do keep pip updated in the user directory with on Ubuntu with no issue. -- Andrea -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 2019-11-01 12:36, Rhodri James wrote: On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. The OP says it prints 44.44. In Python 2, / does integer division, so it would print 44.00. -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 01/11/2019 17:07, MRAB wrote: On 2019-11-01 12:36, Rhodri James wrote: On 31/10/2019 20:14, MRAB wrote: On 2019-10-31 18:46, ferzan saglam wrote: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? My guess is the OP is using Python2 rather than Python3. So my first piece of advice would be to switch to Python3 now so you don't have to re-learn oddities like input(), print() and string handling. The OP says it prints 44.44. In Python 2, / does integer division, so it would print 44.00. Well, it's inconsistent one way or the other. We'll have to wait for more information. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Full stack trace in pdb.post_mortem() ?
I'm trying to understand pdb.post_mortem(), and why the backtrace available in the debugger session seems limited. I posted a similar question on stackoverflow[1], but figured I'd try here as well. Here's a simple program import pdb def inner(): raise Exception("bad stuff") def outer(): try: inner() except Exception as ex: pdb.post_mortem() # using breakpoint() gives the full stack trace, of course def main(): outer() main() When I run that, I get put in the debugger. Then, if I run the `bt` command to get a backtrace, I see: (Pdb) bt /path/to/script(10)outer() -> inner() > /path/to/script(6)inner() -> raise Exception("bad stuff") As you can see, the backtrace only has `outer()` and `inner()`. What happened to `main()`? I want the full stack available, so I can investigate variables, etc. at any point along the chain. (in a real example, there might be quite a lot of additional call frames of interest) For this contrived example, I can put `breakpoint()` instead of `post_mortem()`, and get what I want. But I feel like I'm misunderstanding post-mortem debugging. Is the full call stack simply not available? Note: I am aware that I can *print* the full stack trace (including `main()`), even if it takes some special effort. See these posts: * https://stackoverflow.com/questions/13210436/get-full-traceback/ * https://stackoverflow.com/questions/6086976/how-to-get-a-complete-exception-stack-trace-in-python [1] https://stackoverflow.com/questions/58653016/get-full-backtrace-with-pdb-post-mortem -- https://mail.python.org/mailman/listinfo/python-list
asyncio event guarantees to notify all waiting?
Hello, I'm wondering if set'ing an asyncio.Event guarantees to notify all tasks that are waiting for the event ? Thus even if I `set()` the event and directly `clear()` the event, considering that both thus instructions are no co-routines and thus will not return control to the event-loop, will the wait'ers be notified? I guess so because if I add a 'clear()' directly after the `set` in following example, the waiting task is still notified. However this guarantee is not in the documentation: ``` async def waiter(event): print('waiting for it ...') await event.wait() print('... got it!') async def main(): # Create an Event object. event = asyncio.Event() # Spawn a Task to wait until 'event' is set. waiter_task = asyncio.create_task(waiter(event)) # Sleep for 1 second and set the event. await asyncio.sleep(1) event.set() event.clear() # event directly cleared after being set # Wait until the waiter task is finished. await waiter_task asyncio.run(main()) ``` -- https://mail.python.org/mailman/listinfo/python-list
OOP - iterable class: how to delete one of its objects ?
Hello all, I've created a class from which I can iterate all its instanciated objects (using an "instances" list).The problem is that I now cannot seem to delete an object anymore, AFAIK as a copy of its "self" is still inside the "instances" list. Object in question: - - - - - - - - - - - - - - - - class TheObject: instances = [] def __init__(self): self.instances.append(self) def __del__(self): print("Deleted!") - - - - - - - - - - - - - - - - The question: How can I keep the class iterable, but still have it delete itself when asked. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: OOP - iterable class: how to delete one of its objects ?
On 01/11/2019 19:15, R.Wieser wrote: Hello all, I've created a class from which I can iterate all its instanciated objects (using an "instances" list).The problem is that I now cannot seem to delete an object anymore, AFAIK as a copy of its "self" is still inside the "instances" list. Object in question: - - - - - - - - - - - - - - - - class TheObject: instances = [] def __init__(self): self.instances.append(self) def __del__(self): print("Deleted!") - - - - - - - - - - - - - - - - The question: How can I keep the class iterable, but still have it delete itself when asked. Use weak references. A WeakSet (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is probably what you want. The idea is that the reference to the instance kept by the WeakSet doesn't contribute to the reference count. This won't automatically delete the reference from the WeakSet when the instance goes away, you'll want to set a finalizer for that, but the documentation covers what you want to know fairly clearly. Trust me, I was doing exactly this a week or so ago, and it's pretty straightforward. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: OOP - iterable class: how to delete one of its objects ?
On Sat, Nov 2, 2019 at 6:21 AM R.Wieser wrote: > > Hello all, > > I've created a class from which I can iterate all its instanciated objects > (using an "instances" list).The problem is that I now cannot seem to > delete an object anymore, AFAIK as a copy of its "self" is still inside the > "instances" list. > > Object in question: > - - - - - - - - - - - - - - - - > class TheObject: > instances = [] > > def __init__(self): > self.instances.append(self) > > def __del__(self): > print("Deleted!") > - - - - - - - - - - - - - - - - > > The question: How can I keep the class iterable, but still have it delete > itself when asked. > Have a method to explicitly purge the instance. The "del" statement does NOT request that the object be deleted; it simply unbinds the name. Instead, try something like this: class TheObject: instances = [] def __init__(self): self.active = True self.instances.append(self) def destroy(self): if not self.active: return self.active = False # wipe any attributes you need to self.instances.remove(self) Then, instead of "del some_object", use "some_object.destroy()". You can also use weak references if you need to, but this technique is going to be a lot more reliable and dependable than something based on weakrefs. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
TLDR; declare if homework; doing someone's homework doesn't really help; Python is not ALGOL/Pascal/C/C++ by any other name; Python assignments should promote learning semantics as well as syntax; sometimes re-stating the problem leads to an alternate/better solution. On 31/10/19 12:55 AM, ferzan saglam wrote: I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) --- total = 0 while True: print('Cost of item') item = input() if item != -1: total += int(item) else: break print(total) --- A critique of this thread, plus a suggested approach to a solution:- 1 the OP This is a contrived coding problem. Is it part of a course? To establish an honest relationship with your list-colleagues, should you have declared it as 'homework'? Remembering that no-one 'here' is paid to be helpful, did you politely respond with the clarification requested? (see also later threads) There is an interesting psychology that you will notice when working with other people who are happy to be helpful (per this list-community); that if one stops to think about *how* to pose a question, sometimes the answer 'appears' - a burst of inspiration in your mind. That can be difficult to remember if you've been struggling with a problem for hours with the resultant level of frustration. At least the title of the post: "How can i stop this Infinite While Loop" is descriptive. Compared with some first-time poster's titles, this is clear and competent. Thanks! Thinking about it though, is there a hint of the nature of the problem, or even then an answer, in there? ie pausing to think about it, is the problem actually the "stop" (as emphasised) or might it be the "while"? (more below) 2 respondents This was an 'easy answer' question, so "well done" and "thank you" for jumping-in with the intention of contributing something to the community - quite possibly a first post for some. I encourage you to participate and do NOT wish to criticise you for having the best of motivations. However, it is always a good idea to consider not only "the question", as asked, but to 'first ask why?' (which happens to (almost) be the title of a thoroughly-recommendable book for managers, potential-managers, and certainly coaches/mentors to read). You can see this in one respondent's <>> If (and this is *my* assumption!), the OP is a student attempting to learn Python, cf an experienced pythonista; giving "the answer" is NOT as helpful as it might seem. That's why the "pseudo code" solution was 'better' than a Python equivalent. What should the OP learn? Given 'the answer', would the OP be able to solve a similar problem when next encountered? If the OP's learning-objective is 'Python', then the pseudo-code helped clarify the necessary thinking, without detracting from the OP's learning-opportunity. (cf an algorithms course) In fact, and quite coincidentally, the best learning-opportunity here, has probably been the "off by one" experience - which the OP did indeed learn for himself. (Well done!) 3 the question itself/the questioner The way the OP has attempted to solve this contrived-problem indicates a fundamental lack of understanding of the way Python works and/or the way pythonista think. However, the way the question has been posed indicates much the same! It smacks of an old, even ancient, ComSc problem; previously applied to other languages (something I might have written when learning/teaching FORTRAN more than four decades ago, for example). How does this coding-problem contribute to the *Python* learning process? (as well as contributing towards the learning ComSc principles, eg managing/terminating loops) Thus: The output I am aiming for is for the code to stop asking 'Cost of item' after 10 inputs or until -1 is typed, but the code repeats itself on an infinite loop. I cannot seem to stop the infinite loop. expresses the problem, but in the manner of other languages. The focus has been put on the "-1" fact - how to "stop". (remember the OP's title!) Question: since we no longer present data as decks of punched-cards, what is today's more usual way to indicate EOF/EOD? ("end of file", "end of data") Is the minus-one "flag" a very good approach, or even particularly representative of work-place 'realities'? Towards a solution: OK, let's not argue the point - it's certainly beyond the OP's control, so we must consider it a "specification"... The advice for solving ComSc (and other) problems is always to 'break down the larger problem into smaller, sub-problems and solve them' (which may, in-turn, involve breaking the sub-problems into smaller...) Here 'the problem' may decompose into: 1 accept input value 2 accumulate (total) input data-values 3
[RELEASED] Python 3.5.9 is released
On behalf of the Python development community, I'm slightly chagrined to announce the availability of Python 3.5.9. There were no new changes in version 3.5.9; 3.5.9 was released only because of a CDN caching problem, which resulted in some users downloading a prerelease version of the 3.5.8 .xz source tarball. Apart from the version number, 3.5.9 is identical to the proper 3.5.8 release. This new version is a source-only release. You can find Python 3.5.9 here: https://www.python.org/downloads/release/python-359/ Happy Halloween, /arry -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble trying to get started with pygame
On Friday, November 1, 2019 at 1:05:35 AM UTC-4, MRAB wrote: > On 2019-11-01 03:47, originallmo...@gmail.com wrote: > > It's been years since I've done anything with Python, and it wasn't a > > language I was terribly familiar with even then. I'm using Python 3.8 on my > > Windows 7 laptop. Python itself works so far as I can tell. I can get it to > > import pip without problems, but, when I try to get going with pygame, I > > hit a roadblock. > > > > I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping > > it, yet, I think I've seen things on other forums suggesting that Python > > can do that for me. Is that true? > > > Actually, you do have the means: Python! > > But there's a simpler way. > > > I've been trying to use "pip install" (Written just like that, minus the > > quotes, of course), yet, it tells me that's a syntax error. > > > > Is there a way of inputting this that I'm not aware of? I've seen various > > versions of people calling the command, with things like "pip.install" or > > "-m pip install -U pygame -user" or something like that, are THOSE what I > > should be trying or...am I completely off-base right now? > > > Those commands are for the Windows command prompt. > > > Any help would be appreciated, as I'm losing patience with it at the moment. > > > > Go to Christoph Gohlke's site at: > > https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame > > Download one of these "wheel" files: > > pygame‑1.9.6‑cp38‑cp38‑win_amd64.whl for 64-bit > > or: > > pygame‑1.9.6‑cp38‑cp38‑win32.whl for 32-bit > > At the Windows command prompt type: > > py -3.8 -m pip install "path/to/wheel" Does it matter where I place pygame? I was going to put it into my Scripts folder, as I'm pretty sure I already have a path that goes there. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble trying to get started with pygame
I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble trying to get started with pygame
On 2019-11-02 01:55, originallmo...@gmail.com wrote: On Friday, November 1, 2019 at 1:05:35 AM UTC-4, MRAB wrote: On 2019-11-01 03:47, originallmo...@gmail.com wrote: > It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. > > I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? > Actually, you do have the means: Python! But there's a simpler way. > I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. > > Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? > Those commands are for the Windows command prompt. > Any help would be appreciated, as I'm losing patience with it at the moment. > Go to Christoph Gohlke's site at: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame Download one of these "wheel" files: pygame‑1.9.6‑cp38‑cp38‑win_amd64.whl for 64-bit or: pygame‑1.9.6‑cp38‑cp38‑win32.whl for 32-bit At the Windows command prompt type: py -3.8 -m pip install "path/to/wheel" Does it matter where I place pygame? I was going to put it into my Scripts folder, as I'm pretty sure I already have a path that goes there. It'll be installed into Python's site-packages folder. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble trying to get started with pygame
On 2019-11-02 02:28, originallmo...@gmail.com wrote: I tried what you suggested at the command prompt and (Despite being able to open Python from my start menu), it tells me Python isn't installed. I'm curious, and, I probably should have mentioned it earlier: I have Python on my D drive (Because it has more space). Is THAT why it says Python isn't installed? MUST I have it on the C drive? Do you mean that it can't find "py" or that "py" can't find Python? If you used the installer to install Python on the D drive, then I'd expect it to just work. -- https://mail.python.org/mailman/listinfo/python-list
Re: Friday finking: TDD and EAFP
On Fri, Nov 1, 2019 at 12:42 AM DL Neil via Python-list wrote: > > Is the practice of TDD fundamentally, if not philosophically, somewhat > contrary to Python's EAFP approach? > [...] > > In encouraging my mind to think about testing the code, I find myself > searching for edge-cases, and attempting to anticipate the unusual. > Accordingly to the gospel of TDD: so far, so good. > > The 'problem' is, that it puts my mind onto LBYL-rails before the > Python-coding train (of thought) has even left the station. It then > seems natural to start putting a bunch of if-then-else's up-front and > before the 'main line' of code. > > Does TDD bend your mind in this (apparently) non-Pythonic fashion? > Have you developed an answer? > (other than: "@dn is 'nuts'*", which is not worthy of debate) As the pros have yet to chime in, I will attempt to add my amateurish thoughts. In my on again/off again efforts to self-study Python, sound software construction practices, etc., I have been endeavoring to adopt a TDD approach. I find that trying to do this forces upon me more clarity of thought which (hopefully) results in more expressive, simpler and understandable code. As I often find my initial efforts at writing tests murky and hard to understand, I (eventually) realize that the associated code I'm trying to test, which seemed so clear when I first wrote it, is hard to test. So I refactor/simplify the code, it becomes easier to write sensible test code, etc. It may just be me and my lack of experience, but I find this circular process ultimately leads to more Pythonic results -- easier to understand code that (I hope) others can easily read and understand. Though I am sure I am stating the obvious, instead of just thinking about edge cases, I like to have at least one test that proves that what I normally expect to get is, in fact, gotten. I often embarrassingly find myself caught in some sort of simple logic error that this type of test will catch, especially later if I am refactoring my code in the direction I am trying to coerce it to go for the end product. I am probably far from thinking/coding in a proper Pythonic fashion, but the TDD back-and-forth process seems to get me closer to being Pythonic. -- boB -- https://mail.python.org/mailman/listinfo/python-list
Re: keying by identity in dict and set
On Sun, Oct 27, 2019, at 03:24, Steve White wrote: > Yes, there are several options, but they all involve an extra layer > that detracts between the interface I am building and my user's code. > In this situation, the objects being used as keys are conceptually the > unique entities that the user deals with, even if their data is > non-unique. And I do not want to subject the user to the un-pythonic > use of some operator other than '==' to determine their equivalence. I'm honestly a little bit confused as to what the type of the objects you are using which it's reasonable to do this with but doesn't already work that way > As near as I can tell, returning the id() in __hash__() results in a > perfect hash key. I really want to know if that is true. > Because if it is true, any further layer is simply covering for a > failing in the documentation. And if you can override __hash__ you can, obviously, also override __eq__ to do whatever you want. You can return id in both. In fact, that is the default behavior of objects, assuming your type is not inherited from another type that does something different. Regardless, __hash__ and __eq__ should be consistent with each other. -- https://mail.python.org/mailman/listinfo/python-list
Re: OOP - iterable class: how to delete one of its objects ?
Chris, > Have a method to explicitly purge the instance. I was thinking of that too but decided against it, as it would mean that my objects would need to be handled specially - which is not quite what I'm looking for. To be honest, I was thinking of/hoping that there would be a method which was called when an objects reference count was changed. Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: OOP - iterable class: how to delete one of its objects ?
Dennis, > In __init__() you are adding "self" to a classwide list. So in > your __del__() you need to remove the instance from the > same list. Something :-) Thats the problem: __del__ only gets called when the object is destroyed - which will never happen when the "instances" list still contains a reference to it. Its a catch-22 situation: __del__ needs to be executed to remove the reference from the "instances" list, but I need to remove the reference from that list before __del__ will be called ... Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list
Re: OOP - iterable class: how to delete one of its objects ?
Rhodri, > Use weak references. A WeakSet > (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is > probably what you want. Most likely!As a fresh freshling in regard to python I was not even aware that a "copy object, but do not increment the reference count" existed.Thank you. Could cause some interresting "the object has disappeared!" problems when you're not carefull with it though ... :-) Regards, Rudy Wieser -- https://mail.python.org/mailman/listinfo/python-list