Re: Lesson 39 of Learning Python the Hard Way hangs (Fixed?)
Le 09/09/2015 20:58, Gary Roach a écrit : On 09/09/2015 01:45 PM, John Gordon wrote: In Gary Roach writes: Traceback (most recent call last): File "/root/mystuff/mystuff/ex39_test.py", line 6, in hashmap.set(states, 'Oregon', 'OR') File "/root/mystuff/mystuff/hashmap.py", line 50, in set i, k, v = get_slot(aMap, key) TypeError: 'NoneType' object is not iterable Execution Successful! Where does the message "Execution Successful!" come from? It seems like you have other code that you haven't shown us. In any case, I saved your code and ran it, and did not get an error. No other code. Ninja-IDE tacked the "Execution Successful" at the end if the error message. Dont know why. Interesting that you ran the code successfully. I have tried to run the code in both Ninja and at the command line and got the exact same error message. A note: If you could, please post your replies to the list. If you don't, it either breaks the thread or ends up sending a copy to my personal email address. I am assuming that your email client gives you that choice. If not, I'm not sure how you would assure that the proper way happens. I use the icedove (thunderbird) mail client and the choice is a drop down list at the top of the mail editor page. Thanks for your reply. Still confused Gary R. PS I copied over my code with the one from the lesson and all of a sudden it works. I then used the code I copied to the email. It also worked. Now I can't duplicate the problem. The problems fixed but So something was *necessarely* different between your test and what you've posted here (which works for me as well, without error). Your first tests were different from what you've posted, this is certain. Could be because you redefined "list" in your module, you shouldn't: >>> list('abcd') ['a', 'b', 'c', 'd'] >>> def list(aMap): ... """Prints out what's in the Map.""" ... for bucket in aMap: ... if bucket: ... for k, v in bucket: ... print k, v >>> list('abcd') Traceback (most recent call last): File "", line 1, in File "", line 5, in list ValueError: need more than 1 value to unpack So if you've been using "list" as a constructor *after* def list... *in your module* it wouldn't have behaved as expected. As a rule of thumb : do not use types names (list, str, tuple, ...) as identifiers in your code. Most of the times it is harmless first, (especially in modules, because of namespaces isolation) but sooner or later it leads to strange errors... >>> list(message) ['h', 'e', 'l', 'l', 'o'] >>> list = [1,2,3] >>> list(message) Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable -- https://mail.python.org/mailman/listinfo/python-list
Re: when may sys.executable be empty
Le 11/03/2015 15:41, Wolfgang Maier a écrit : From the documentation of sys.executable: A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None. So on which systems does it not make sense ? Thanks for any help, Wolfgang On this kind of system (python for microcontroller, running on bare metal), I guess: http://micropython.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with for and if
Le 05/01/2015 15:27, Dariusz Mysior a écrit : I want search count of szukana in zmienna but code below counting all 12 letters from "traktorzysta" word szukana="t" zmienna="traktorzysta" def gen(): count=int(0) for a in zmienna: if szukana in zmienna: count+=1 else: continue return count print("Literka '",szukana,"' w słowie ",zmienna, "wystąpiła ",gen()," razy") In the for loop a is iterating through "traktorzysta" ("t", then "r", then "a", ...): 12 steps moreover the expression szukana in zmienna is always true (as t is a letter of "traktorzysta"), so count += 1 is executed twelve times. def gen(): count=int(0) for a in zmienna: if a == szukana: count+=1 else: continue return count will work (even if quite ugly, why int(0)? why defining a function without parameters? etc.) -- https://mail.python.org/mailman/listinfo/python-list
Re: import graphics library; causes error
Le 17/11/2014 04:03, ryguy7272 a écrit : On Sunday, November 16, 2014 3:39:45 PM UTC-5, ryguy7272 wrote: These libraries drive me totally nuts. Sorry, just had to get it out there. Anyway, I open the cmd window, and typed this: 'easy_install python graphics'. So, it starts up and runs/downloads the appropriate library from the web. I get confirmation (in the cmd window) that it finishes, then I try to run this script. # futval_graph2.py from graphics import * [...] In what directory? Well, that's a damn good question. I thought, by defailt, everything was downloaded to this folder: 'C:\Python27\Lib\site-packages' Except when the module does not exist in pypi... In such case either easy_install and pip finish by printing out that the module cannot be found... graphics.py is NOT distributed through pypi, you have to download and copy it by yourself in an appropriate place from the author's Web site: http://mcsp.wartburg.edu/zelle/python/graphics.py It seems there is always a copy, so I cut/paste the folders named 'setuptools' & 'pip' (always taking off the versions and identifiers and the like...). Then I cut/paste everything into this folder: 'C:\Python27\Lib' Is that how it's done or not? Honestly, for the life of me, I don't know why a human being would have do do any of this, including using the cmd window, to install anything in 2014. I can code in 10 different languages, not including Python. Python is by far the most backwards type of technology that I can think of. Using it is completely counter-productive. I can't take it serious. I have plenty of tools in my toolbox. I'll keep learning Python, and keep reading books, and keep using it...but strictly for fun. I would never use this as a foundation for a mission critical business application. MS Windows is by far the most backwards type of technology that I can think of. Using it is completely counter-productive. I can't take it serious. I have plenty of tools in my Linux boxes. I would never use MS Windows as a foundation for a mission critical business application. Hopefully I'm not the only one to think so... -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to run print('Réussi') on windows and on linux
Le 14/08/2014 16:04, marc.vanhoomis...@gmail.com a écrit : Hello YBM, I tried your suggestions, without improvement. Further, see my answer to Vincent Vande Vyre Thanks anyway. This is indeed very surprising. Are you sure that you have *exactly* this line at the first or second (not later !) line of your script : # -*- encoding: utf-8 -*- if a single caracter differs, it would fail. -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to run print('Réussi') on windows and on linux
Le 14/08/2014 14:35, marc.vanhoomis...@gmail.com a écrit : Hello, This very simple program runs well on windows 7 # -*- utf8 -*- print('Réussi') But, when I start the vrey same file on Linux (ubuntu 14), I got: Traceback (most recent call last): File "/partages/bureau/PB/Dev/Python3/test.py", line 2, in print('R\xe9ussi') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128) What should i do to let the same program run on both OS, without changes? the correct comment line should be : # -*- encoding: utf-8 -*- and it could be usefull to begin with #!/usr/bin/env python or #!/usr/bin/env python3 : $ cat > réussi.py #!/usr/bin/env python # -*- encoding: utf-8 -*- print('Réussi'); ^D $ chmod +x réussi.py $ ./réussi.py Réussi $ python réussi.py Réussi -- https://mail.python.org/mailman/listinfo/python-list
Re: how to change the time string into number?
Le 14/08/2014 04:16, Tim Chase a écrit : On 2014-08-13 21:01, Tim Chase wrote: On 2014-08-14 09:46, luofeiyu wrote: s="Aug" how can i change it into 8 with some python time module? >>> import time >>> s = "Aug" >>> time.strptime(s, "%b").tm_mon 8 works for me. Or, if you want a more convoluted way: >>> import calendar as c >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() 8 it's a joke isn't it ? >>> import calendar as c >>> list(c.month_abbr).index('Aug') 8 BTW, why iterators does not have such an index method ? >>> iter(c.month_abbr).index('Aug') Traceback (most recent call last): File "", line 1, in AttributeError: 'iterator' object has no attribute 'index' -- https://mail.python.org/mailman/listinfo/python-list
Re: dictionary with tuples
Le 14/01/2014 23:00, Tobiah a écrit : On 01/14/2014 01:21 PM, YBM wrote: Le 14/01/2014 22:10, Igor Korot a écrit : Hi, ALL, C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. dict = {} dict[(1,2)] = ('a','b') dict[(3,4)] = ('c','d') for (key1,key2),(value1,value2) in dict: ... print key1, " ", key2 ... print value1, " ", value2 ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable What am I doing wrong? for ... in dict: is a way to iterate through dictionnary items, what you want to do can be done so: for (key1,key2),(value1,value2) in dict.items(): But it's (key1, value1), (key2, value2) No. Try it. key1 key2 are the members of every tuple key. value1, value2 are the members of every tuple value. >>> d={ (1,2):('a','b'), (3,4):('c','d') } >>> for (key1,key2),(value1,value2) in d.items(): ... print key1,key2,value1,value2 ... 1 2 a b 3 4 c d -- https://mail.python.org/mailman/listinfo/python-list
Re: dictionary with tuples
Le 14/01/2014 22:10, Igor Korot a écrit : Hi, ALL, C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. dict = {} dict[(1,2)] = ('a','b') dict[(3,4)] = ('c','d') for (key1,key2),(value1,value2) in dict: ... print key1, " ", key2 ... print value1, " ", value2 ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable What am I doing wrong? for ... in dict: is a way to iterate through dictionnary items, what you want to do can be done so: for (key1,key2),(value1,value2) in dict.items(): -- https://mail.python.org/mailman/listinfo/python-list
Re: python programming help
Le 08.12.2013 19:32, rafaella...@gmail.com a écrit : On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: On 12/8/2013 12:59 PM, rafaella...@gmail.com wrote: i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. please help Welcome to the python list. Thanks for posting a question. If you were hoping for one of us to write the program for you ... well that's not what we do on this list. Please post the code you have so far and tell us exactly where you need help. Also tell us what version of Python, what OS, and what you use to write and run Python programs. name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] dic={} def combine_lists(name,age): for i in range(len(name)): dic[name[i]]= age[i] combine_lists(name,age) print dic def people(age): people=lambda age: [name for name in dic if dic[name]==age] people(20) this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result You didn't write a function which return a result, so you have no result. -- https://mail.python.org/mailman/listinfo/python-list
Re: python programming help
Le 08.12.2013 20:06, rafaella...@gmail.com a écrit : i get it, thanks a lot i wrote a different one and it works def people(age): people=[name for name in dic if dic[name]==age] print(people) No it doesn't. You are printing things not returning something. and combine_list is the most stupidest function you could write in Python, as it is built-in with the name 'zip'. >>> name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] >>> age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] >>> dic = dict(zip(name,age)) >>> def people(age): ... ''' How stupid it is to write three line for a one-line function''' ... return [name for name in dic if dic[name]==age] ... >>> people(20) ['Gary', 'Alice', 'Frank'] Sorry for having being rude, but : 1. you shouldn't post raw homework in any kind of public group (aren't you supposed to learn something by yourself ?) 2. your teacher is a nut. -- https://mail.python.org/mailman/listinfo/python-list
Re: python programming help
Le 09.12.2013 01:00, Gregory Ewing a écrit : rafaella...@gmail.com wrote: def people(age): people=lambda age: [name for name in dic if dic[name]==age] but i don't get the lambda age part. Just to explain: YBM has tried to sabotage you by posting a solution that uses a couple of advanced Python features (lambda and list comprehensions) that a beginner would be unlikely to know about. Oh! I've been caught! ;-) My point is not that I had a problem with the OP (btw asking for homework in a public group always irrates me), but that the teacher of the OP is incredibly stupid and illiterate (or should I say illluterate ?) So I tried to catch both. -- https://mail.python.org/mailman/listinfo/python-list
Re: python programming help
Le 08.12.2013 19:14, rafaella...@gmail.com a écrit : On Sunday, December 8, 2013 6:07:47 PM UTC, YBM wrote: Le 08.12.2013 18:59, rafaella...@gmail.com a �crit : i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. please help ageDict = { 'john':42, 'jane':36, 'paul':42 } peopleWithAge = lambda age: [ name for name in ageDict if ageDict[name]==age] sorry but i'm new to python ;p 1. it has to be in a form of a function called people and 2. how this code takes in an age and returns the names? >>> ageDict = { 'john':42, 'jane':36, 'paul':42 } >>> people = lambda age: [ name for name in ageDict if ... ageDict[name]==age] >>> people(42) ['paul', 'john'] -- https://mail.python.org/mailman/listinfo/python-list
Re: python programming help
Le 08.12.2013 18:59, rafaella...@gmail.com a écrit : i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. please help ageDict = { 'john':42, 'jane':36, 'paul':42 } peopleWithAge = lambda age: [ name for name in ageDict if ageDict[name]==age] -- https://mail.python.org/mailman/listinfo/python-list
Re: If you continue being rude i will continue doing this
You are the one being rude, Nikos. Moreover you are a nut, installing pygeoip works fine for me: # pip install pygeoip Downloading/unpacking pygeoip Downloading pygeoip-0.3.0.tar.gz (97Kb): 97Kb downloaded Running setup.py egg_info for package pygeoip Installing collected packages: pygeoip Running setup.py install for pygeoip Successfully installed pygeoip Cleaning up... you've probably completely messed up your system, as you are completely incompetent as a UNIX/Linux admin and broke your system. Le 17/11/2013 23:31, Ferrous Cranus a écrit : == root@secure [~/distribute-0.6.49]# pip install pygeoip Downloading/unpacking pygeoip Downloading pygeoip-0.3.0.tar.gz (97kB): 97kB downloaded Running setup.py egg_info for package pygeoip Traceback (most recent call last): File "", line 16, in File "/usr/lib/python3.3/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1098: ordinal not in range(128) Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 16, in File "/usr/lib/python3.3/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1098: ordinal not in range(128) == -- https://mail.python.org/mailman/listinfo/python-list
Re: PYTHON 3.4 LEFTOVERS
Le 17.11.2013 10:12, Nikos a écrit : Στις 16/11/2013 6:46 μμ, ο/η YBM έγραψε: Le 16.11.2013 17:30, Ferrous Cranus a écrit : Mark wrote: If you have to deliberately post like this in an attempt to annoy people, would you please not do so using double spaced google crap as it's very annoying, thank you in anticipation. Sure thing Mark, here: root@secure [~]# find / -name python3.4 | rm -rf root@secure [~]# locate python3.4 /root/.local/lib/python3.4 /usr/local/include/python3.4m /usr/local/lib/libpython3.4m.a /usr/local/lib/python3.4 /usr/local/share/man/man1/python3.4.1 still there!!! You are utterly stupid: 1st: rm does not read its standard input so doing whatever | rm -fr is useless 2st: even if it had worked (i.e. removed the files) they would still appear with locate, as locate is just reading a database build every day by updatedb (using find btw) What you want to do can be done this way : find / -name python3.4 -exec rm -rf {} \; 'find / -name python34 | xargs -rf' does what i need it do certainly not with xargs -rf, but with xargs rm -rf it works similar to find's built-in exec method using as argument whatever matches results to. find / -name python3.4 -exec rm -rf {} So both have same effect i assume. Yes, but they were no xargs in the command lines you wrote originally, Nikos. bla bla | rm ... is not the same as bla bla | xargs rm ... do you suffer of some kind of visual illness? -- https://mail.python.org/mailman/listinfo/python-list
Re: PYTHON 3.4 LEFTOVERS
Le 16.11.2013 18:00, Nikos a écrit : Στις 16/11/2013 6:46 μμ, ο/η YBM έγραψε: Le 16.11.2013 17:30, Ferrous Cranus a écrit : Mark wrote: If you have to deliberately post like this in an attempt to annoy people, would you please not do so using double spaced google crap as it's very annoying, thank you in anticipation. Sure thing Mark, here: root@secure [~]# find / -name python3.4 | rm -rf root@secure [~]# locate python3.4 /root/.local/lib/python3.4 /usr/local/include/python3.4m /usr/local/lib/libpython3.4m.a /usr/local/lib/python3.4 /usr/local/share/man/man1/python3.4.1 still there!!! You are utterly stupid: 1st: rm does not read its standard input so doing whatever | rm -fr is useless 2st: even if it had worked (i.e. removed the files) they would still appear with locate, as locate is just reading a database build every day by updatedb (using find btw) What you want to do can be done this way : find / -name python3.4 -exec rm -rf {} \; updatedb locate python3.4 but you'd better go to hell first. Even if you told me to go to hell i will overcome that and i need to thank you because this indeed worked. Why is this find / -name python3.4 -exec rm -rf {} \; different from: find / -name python3.4 | rm -rf Doesn't any command take its input via STDIN or from a text file or from another's command output? No. Not all UNIX commands are filters. rm is NOT a filter. If the above was true then wouldn't linux displayed an error when i issued: find / -name python3.4 | rm -rf locate python3.4 | rm -rf Because you ask to suppress error output by adding -f The fact that it hasn't and it has indeed deleted many files proved that rm as an other linux command can take input from another's command output. No, it does not prove that, it prove that -f does what it is supposed to do, as you'd have done if you'd done "man rm" : tv@roma:~$ echo a | rm rm: missing operand Try `rm --help' for more information. tv@roma:~$ echo a | rm -f bash: echo: write error: Broken pipe -- https://mail.python.org/mailman/listinfo/python-list
Re: Question regarding 2 modules installed via 'pip'
Le 16.11.2013 16:43, Ferrous Cranus a écrit : Just as you use "which python" to figure out what "python" was executing, >"which pip" will help you figure out what "pip" is running. root@secure [~]# which python3 /usr/bin/python3 root@secure [~]# cd /usr/bin/python3 -bash: cd: /usr/bin/python3: Not a directory root@secure [~]# which pip /usr/bin/pip root@secure [~]# cd /usr/bin/pip -bash: cd: /usr/bin/pip: Not a directory WHAT THE FUCK IS GOING ON WITH THIS DAMN CentOS 6.4? WHY CANT I JUST CD INTO HESE DAMN FOLDERS? What don't you understand in what bash told you with "Not a directory" ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Question regarding 2 modules installed via 'pip'
Le 16.11.2013 16:32, Ferrous Cranus a écrit : root@secure [~]# locate python3.4 /root/.local/lib/python3.4 /usr/local/include/python3.4m /usr/local/lib/libpython3.4m.a /usr/local/lib/python3.4 /usr/local/share/man/man1/python3.4.1 many files of python's 3.4a have been deleted this way, but the aboe displayed persist. I doubt it, find ... | rm ... does absolutely nothing as you'd have figured out by yourself if you had a brain. and then how i'am gonna install those 2 modules for python 3.3.2? I assume you can navigate to the Python 3.3.2 directory where pip is installed and run it from there. root@secure [~]# which python3 /usr/bin/python3 root@secure [~]# cd /usr/bin/python3 -bash: cd: /usr/bin/python3: Not a directory It seems that i cannot even cd into this folder, wtf Perhaps because this is not a folder. Learn to read. -- https://mail.python.org/mailman/listinfo/python-list
Re: PYTHON 3.4 LEFTOVERS
Le 16.11.2013 17:30, Ferrous Cranus a écrit : Mark wrote: If you have to deliberately post like this in an attempt to annoy people, would you please not do so using double spaced google crap as it's very annoying, thank you in anticipation. Sure thing Mark, here: root@secure [~]# find / -name python3.4 | rm -rf root@secure [~]# locate python3.4 /root/.local/lib/python3.4 /usr/local/include/python3.4m /usr/local/lib/libpython3.4m.a /usr/local/lib/python3.4 /usr/local/share/man/man1/python3.4.1 still there!!! You are utterly stupid: 1st: rm does not read its standard input so doing whatever | rm -fr is useless 2st: even if it had worked (i.e. removed the files) they would still appear with locate, as locate is just reading a database build every day by updatedb (using find btw) What you want to do can be done this way : find / -name python3.4 -exec rm -rf {} \; updatedb locate python3.4 but you'd better go to hell first. -- https://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
Le 16.06.2013 13:06, Ferrous Cranus a écrit : what id() does, never heard of that function before. just type help(id) at Python prompt and stop flooding the group with superfluous demands. -- http://mail.python.org/mailman/listinfo/python-list