Re: Reading csv file
Thank you, Peter. About OOP: company policy, can't help it. They say it's easier to maintain and code. But it works now. On Thu, Dec 19, 2013 at 2:39 AM, Peter Otten <__pete...@web.de> wrote: > Igor Korot wrote: > >> Hi, Peter, >> Thank you for the great suggestion. >> >> I tried to implement you code but failed. >> >> Here's what I have: >> >> class FileReader: >> def __init__(self, filename, isSkip): >> self.path = filename >> self.isSkip = isSkip >> >> @contextmanager >> def open(*args): > > Selfless OO? Not in Python. > >> from StringIO import StringIO >> lines = range(10) >> if self.isSkip: >> lines[0] = "skipped" >> lines[6] = "field1-from-line6,field2-from-line6" >> else: >> lines[0] = "field1-from-line1,field2-from-line1" >> yield StringIO("\r\n".join(map(str, lines))) >> >> def is_arbitrary_text(self,fieldnames): >> return "skipped" in fieldnames >> >> def readData(self): >> with self.open(self.path, "r") as f: >> reader = csv.DictReader(f) >> if self.is_arbitrary_text(reader.fieldnames): >> for _ in range(5): >> next(reader, None) >> reader._fieldnames = None > > Here you introduced another bug, ignoring my helpful comments. > >>> reader._fieldnames = None # underscore necessary, >>> # fieldnames setter doesn't work >>> reader.fieldnames # used for its side-effect > >> for row in reader: >> print row >> >> Unfortunately this does not work as "def open()" does not belong to my >> class and if I comment the "@contextmanager" line >> I will get an exception: "AttributeError: __exit__" >> >> Any idea what to do? > > Keeping comments is not an option? But please read and try to understand the > comments before you excise them ;) > > As I mentioned in the comment to the open() function you are not supposed to > use it as you have real data -- use Python's built-in open() function. > Anyway, if you insist on doing everything the OO-way, at least add a self in > all the right places and don't introduce bugs that could be avoided with > copy-and-paste. > > A working script with mock data and following the OO fashion would be: > > $ cat csv_skip_header_oo.py > import csv > from contextlib import contextmanager > > class FileReader: > def __init__(self, filename, isSkip): > self.path = filename > self.isSkip = isSkip > > @contextmanager > def open(self, *args): > from StringIO import StringIO > lines = range(10) > if self.isSkip: > lines[0] = "skipped" > lines[6] = "field1-from-line6,field2-from-line6" > else: > lines[0] = "field1-from-line1,field2-from-line1" > yield StringIO("\r\n".join(map(str, lines))) > > def is_arbitrary_text(self,fieldnames): > return "skipped" in fieldnames > > def readData(self): > with self.open(self.path, "r") as f: > reader = csv.DictReader(f) > if self.is_arbitrary_text(reader.fieldnames): > for _ in range(5): > next(reader, None) > > reader._fieldnames = None # underscore necessary, > # fieldnames setter doesn't work > reader.fieldnames # used for its side-effect > > for row in reader: > print row > > if __name__ == "__main__": > import sys > print "Demo with made-up data" > skip = len(sys.argv) > 1 and sys.argv[1] == "--skip" > if skip: > print "Variant 2, header is skipped" > else: > print "Variant 1, no header" > FileReader("whatever.csv", skip).readData() > > $ python csv_skip_header_oo.py > Demo with made-up data > Variant 1, no header > {'field2-from-line1': None, 'field1-from-line1': '1'} > {'field2-from-line1': None, 'field1-from-line1': '2'} > {'field2-from-line1': None, 'field1-from-line1': '3'} > {'field2-from-line1': None, 'field1-from-line1': '4'} > {'field2-from-line1': None, 'field1-from-line1': '5'} > {'field2-from-line1': None, 'field1-from-line1': '6'} > {'field2-from-line1': None, 'field1-from-line1': '7'} > {'field2-from-line1': None, 'field1-from-line1': '8'} > {'field2-from-line1': None, 'field1-from-line1': '9'} > $ python csv_skip_header_oo.py --skip > Demo with made-up data > Variant 2, header is skipped > {'field1-from-line6': '7', 'field2-from-line6': None} > {'field1-from-line6': '8', 'field2-from-line6': None} > {'field1-from-line6': '9', 'field2-from-line6': None} > > A script using real data would be: > > $ cat csv_
Re: PDFMiner install question
Jason Mellone wrote: >I get the following error: >PS C:\USERS\Python27> .\python.exe .\MyTest.py >Traceback (most recent call last): > File ".\MyTest.py", line 4, in >from pdfminer.pdfpage import PDFTextExtractionNotAllowed >ImportError: cannot import name PDFTextExtractionNotAllowed > > >If I run commenting out the import of "PDFTextExtractionNotAllowed" it >runs without a problem. Quite odd. According to the latest version on Github, "PDFTextExtractionNotAllowed" was moved into the "PDFPage" class, but the sample code in the docs was obviously not updated. https://github.com/euske/pdfminer/blob/master/pdfminer/pdfpage.py So just leave out that line and if you need that exception use "PDFPage.PDFTextExtractionNotAllowed" instead of "PDFTextExtractionNotAllowed". Bye, Andreas -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining whether a glyph is available in Tkinter
Le vendredi 20 décembre 2013 00:10:58 UTC+1, wmcb...@gmail.com a écrit : > On Monday, December 16, 2013 10:58:06 PM UTC-5, Terry Reedy wrote: > > > In this case, I already know that the glyphs I chose work with the default > fonts for OS X 10.4+ and Windows 7+, but not for (for example) Win XP. > > As I pointed in an another thread, Windows 7 is the first Windows which became full unicode compliant (0th order approximation). If your application works fine with win7, good. If it does not on XP, it's like this. --- Font: I do not know what glyphs you "need". Do not expect to find always a single font that will cover your needs. It's a little bit a side effect of "unicode", but everything has been constructed to be a no problem. And it is a no problem. jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: How to use the method loadtxt() of numpy neatly?
On Friday, December 20, 2013 11:18:53 AM UTC+5:30, chao dong wrote: > HI, everybody. When I try to use numpy to deal with my dataset in the style > of csv, I face a little problem. > In my dataset of the csv file, some columns are string that can not > convert to float easily. Some of them can ignore, but other columns I need to > change the data to a enum style. > for example, one column just contain three kinds : S,Q,C. Each of them > can declare one meaning, so I must convert them to a dict just like {1,2,3} What does "dict like {1,2,3}" mean?? On recent python thats a set On older ones its probably an error. So you can mean one of: 1. Set([1,2,3]) 2. List: [1,2,3] 3. Tuple: (1,2,3) 4. Dict: {"S":1, "Q":2, "C":3} 5. An enumeration (on very recent pythons) 6. A simulation of an enum using classes (or somesuch) 7. Something else > Now the question is, when I use numpy.loadtxt, I must do all things above > in just one line and one fuction. So as a new user in numpy, I don't know how > to solve it. I suggest you supply a couple of rows of your input And the corresponding python data-structures you desire Someone should then suggest how to go about it -- https://mail.python.org/mailman/listinfo/python-list
Re: How to use the method loadtxt() of numpy neatly?
chao dong wrote: > HI, everybody. When I try to use numpy to deal with my dataset in the > style of csv, I face a little problem. > > In my dataset of the csv file, some columns are string that can not > convert to float easily. Some of them can ignore, but other columns I > need to change the data to a enum style. > > for example, one column just contain three kinds : S,Q,C. Each of them > can declare one meaning, so I must convert them to a dict just like > {1,2,3} > > Now the question is, when I use numpy.loadtxt, I must do all things > above in just one line and one fuction. So as a new user in numpy, I > don't know how to solve it. > > Thank you. Here's a standalone demo: import numpy _lookup={"A": 1, "B": 2} def convert(x): return _lookup.get(x, -1) converters = { 0: convert, # in column 0 convert "A" --> 1, "B" --> 2, # anything else to -1 } if __name__ == "__main__": # generate csv with open("tmp_sample.csv", "wb") as f: f.write("""\ A,1,this,67.8 B,2,should,56.7 C,3,be,34.5 A,4,skipped,12.3 """) # load csv a = numpy.loadtxt( "tmp_sample.csv", converters=converters, delimiter=",", usecols=(0, 1, 3) # skip third column ) print a Does that help? -- https://mail.python.org/mailman/listinfo/python-list
Why Python is like C++
http://xkcd.com/1306/ -- https://mail.python.org/mailman/listinfo/python-list
Struggling with unittest discovery - how to structure my project test suite
I'm trying to write a project using test-first development. I've been basically following the process from "Test-Driven Web Development with Python" (excellent book, by the way) but I'm writing a command line application rather than a web app, so I'm having to modify some bits as I go along. Notably I am *not* using the django test runner. I have my functional tests in a file in my project root at the moment - functional_tests.py. But now I need to start writing some unit tests and I need to refactor my tests into a more manageable structure. If I create a "tests" directory with an __init__.py and "unit" and "functional" subdirectories, each with __init__.py and test_XXX.py files in them, then "python -m unittest" works (as in, it discovers my tests fine). But if I just want to run my unit tests, or just my functional tests, I can't seem to get the command line right to do that - I either get all the tests run, or none. What's the best way of structuring my projects so that: 1. I can run all the tests easily on demand. 2. I can run just the functional or unit tests when needed. 3. I can run individual tests (or maybe just individual test modules, I don't have so many tests yet that I know how detailed I'll need to get!) without too much messing (and certainly without changing any source files!) I know that tools like py.test or nose can probably do this sort of thing. But I don't really want to add a new testing tool to the list of things I have to learn for this project (I'm already using it to learn SQLAlchemy and colander, as well as test-driven development, so I have enough on my plate already!) I've looked around on the web for information - there's a lot available on writing the tests themselves, but surprisingly little on how to structure a project for easy testing (unless I've just failed miserably to find the right search terms :-)) Thanks for any help, Paul -- https://mail.python.org/mailman/listinfo/python-list
Newbie question. Are those different objects ?
y = raw_input('Enter a number:') print type y y = float(raw_input('Enter a number:')) print type y I'm assuming that y is an object. I'm also assuming that the second and the first y are different objects because they have different types. The second time we type print type y, how does the program knows which one of the y's it refers to ? Is the first y object deleted ? thanks in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On Fri, Dec 20, 2013, at 10:16, dec...@msn.com wrote: > The second time we type print type y, how does the program knows which > one of the y's it refers to ? Is the first y object deleted ? y does not refer to the first object anymore after you've assigned the second object to it. In CPython, if there are no other references to the string object, yes it is deleted - other implementations may defer deletion to a later time. -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On Friday, December 20, 2013 8:46:31 PM UTC+5:30, dec...@msn.com wrote: > y = raw_input('Enter a number:') > print type y > y = float(raw_input('Enter a number:')) > print type y > I'm assuming that y is an object. I'm also assuming that the second and the > first y are different objects because they have different types. You are also assuming that the two horizontal lines sometimes called 'equals' have something to do with something called by the same name in math -- equations Lets unassume that and rewrite the code 1. y ! raw_input('Enter a number:') 2. print type y 3. y ! float(raw_input('Enter a number:')) 4. print type y Now read that 1 as first, 2 as second etc and read the '!' as 'MAKE'. (It may help to shout it) Now what was your question? -- https://mail.python.org/mailman/listinfo/python-list
wxPython latest
As wxPython was mentioned a week ago some of you may be interested in these http://article.gmane.org/gmane.comp.python.wxpython.devel/5680 http://article.gmane.org/gmane.comp.python.wxpython.devel/5675 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 20/12/2013 15:34, rusi wrote: On Friday, December 20, 2013 8:46:31 PM UTC+5:30, dec...@msn.com wrote: y = raw_input('Enter a number:') print type y y = float(raw_input('Enter a number:')) print type y I'm assuming that y is an object. I'm also assuming that the second and the first y are different objects because they have different types. You are also assuming that the two horizontal lines sometimes called 'equals' have something to do with something called by the same name in math -- equations A good point. Shall I write a PEP asking for a language change which requires that that stupid = sign is replaced by a keyword reading something like thenameonthelefthandsideisassignedtheobjectontherighthandside ? Lets unassume that and rewrite the code 1. y ! raw_input('Enter a number:') 2. print type y 3. y ! float(raw_input('Enter a number:')) 4. print type y Now read that 1 as first, 2 as second etc and read the '!' as 'MAKE'. (It may help to shout it) Now what was your question? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 12/20/2013 10:16 AM, dec...@msn.com wrote: print type y That line will give you a syntax error. -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On Friday, December 20, 2013 9:30:22 PM UTC+5:30, Mark Lawrence wrote: > On 20/12/2013 15:34, rusi wrote: > > On Friday, December 20, 2013 8:46:31 PM UTC+5:30, dec...@msn.com wrote: > >> y = raw_input('Enter a number:') > >> print type y > >> y = float(raw_input('Enter a number:')) > >> print type y > >> I'm assuming that y is an object. I'm also assuming that the second and > >> the first y are different objects because they have different types. > > You are also assuming that the two horizontal lines sometimes called > > 'equals' > > have something to do with something called by the same name in math -- > > equations > A good point. Shall I write a PEP asking for a language change which > requires that that stupid = sign is replaced by a keyword reading > something like > thenameonthelefthandsideisassignedtheobjectontherighthandside ? Good idea. Only you were beaten to it by about 2 decades. The language ABC calls it 'put' and corrects the unnecessary gratuitous right to left order. Reference http://homepages.cwi.nl/~steven/abc/qr.html#COMMANDS Examples http://homepages.cwi.nl/~steven/abc/types.html And what does that have to do with python? http://www.onlamp.com/lpt/a/2431 -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 20/12/2013 17:10, rusi wrote: On Friday, December 20, 2013 9:30:22 PM UTC+5:30, Mark Lawrence wrote: On 20/12/2013 15:34, rusi wrote: On Friday, December 20, 2013 8:46:31 PM UTC+5:30, dec...@msn.com wrote: y = raw_input('Enter a number:') print type y y = float(raw_input('Enter a number:')) print type y I'm assuming that y is an object. I'm also assuming that the second and the first y are different objects because they have different types. You are also assuming that the two horizontal lines sometimes called 'equals' have something to do with something called by the same name in math -- equations A good point. Shall I write a PEP asking for a language change which requires that that stupid = sign is replaced by a keyword reading something like thenameonthelefthandsideisassignedtheobjectontherighthandside ? Good idea. Only you were beaten to it by about 2 decades. I can't find a PEP suggesting this, can you give me the number please? The language ABC calls it 'put' and corrects the unnecessary gratuitous right to left order. So does it go top to bottom or bottom to top? Or to really clarify things does it have putlr, putrl, puttb and putbt? Reference http://homepages.cwi.nl/~steven/abc/qr.html#COMMANDS Examples http://homepages.cwi.nl/~steven/abc/types.html And what does that have to do with python? http://www.onlamp.com/lpt/a/2431 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Struggling with unittest discovery - how to structure my project test suite
20.12.13 16:47, Paul Moore написав(ла): What's the best way of structuring my projects so that: 1. I can run all the tests easily on demand. 2. I can run just the functional or unit tests when needed. python -m unittest discover -s tests/functional python -m unittest discover tests/functional 3. I can run individual tests (or maybe just individual test modules, I don't have so many tests yet that I know how detailed I'll need to get!) without too much messing (and certainly without changing any source files!) python -m unittest discover -s tests/functional -p test_spam.py python -m unittest discover tests/functional -p test_spam.py python -m unittest discover tests/functional test_spam.py -- https://mail.python.org/mailman/listinfo/python-list
Re: Why Python is like C++
20.12.13 16:19, Roy Smith написав(ла): http://xkcd.com/1306/ QBASIC$, not $QBASIC. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
This thread hasn't been close to Python for while now and should be shut down. But, it is actually kind of interesting since you debate possible mechanisms behind the behaviour of my Windows box at work: "Not responding" is happening to me daily for any application including Microsoft's own Office Suite. I hoped it would go away when we moved from Vista to W7 but it didn't. In all fairness, our computers have both corporate and HP crapware installed so Microsoft may be innocent. Coming from many years of SUN Solaris experience I may be a bit spoiled when it comes to robustness :-) Now, let's leave this behind and spend time on Python -- something I with a formal programming education dating back to 1980 and F77 find fascinating. /Martin -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On Saturday, December 21, 2013 1:10:37 AM UTC+8, rusi wrote: > On Friday, December 20, 2013 9:30:22 PM UTC+5:30, Mark Lawrence wrote: > > > On 20/12/2013 15:34, rusi wrote: > > > > On Friday, December 20, 2013 8:46:31 PM UTC+5:30, dec...@msn.com wrote: > > > >> y = raw_input('Enter a number:') > > > >> print type y > > > >> y = float(raw_input('Enter a number:')) > > > >> print type y > > > >> I'm assuming that y is an object. I'm also assuming that the second and > > >> the first y are different objects because they have different types. > Well, in Python the assignment operation = of a variable named y in the LHS to the object of the RHS result is more complicated than = in those register basd low level languages designed for fast execution speeds in compiled machine codes without an auto GC bundled with the interpreter in the run time. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
On 20/12/2013 17:52, Martin Schöön wrote: Coming from many years of SUN Solaris experience I may be a bit spoiled when it comes to robustness :-) You never had the pleasure of working on VMS then? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 12/20/2013 08:16 AM, dec...@msn.com wrote: > y = raw_input('Enter a number:') > print type y > y = float(raw_input('Enter a number:')) > print type y > > I'm assuming that y is an object. Rather than thinking that y "is" an object, it is more accurate to think of it as: y is a name that is "bound" to (ie, refers to, points to) an object. So, raw_input() creates a string object and returns it. Your first assignment statement binds that string object to the name "y". From now on, when you refer to "y" you will get that string object. When python executes your 3rd line, raw_input() creates a new string object, completely separate from the earlier one. This object is passed to float(). Float() reads it and creates a new float object and returns it. When python then executes your second assignment statement, it changes the binding of "y" to point to the float object; the old binding to the string object is lost. From now on, when you refer to "y" you will get the float object. > I'm also assuming that the second and the first y are different > objects because they have different types. Yes, they are different objects. But not because they have different types; they are different because every time python creates a new object it is distinct from other objects [*1]. > The second time we type > print type y, how does the program knows which one of the y's it > refers to ? Because there is only one name "y", and when python executed your second assignment statement, it changed the object that the name y pointed to from the first (string) object to the second (float) one. > Is the first y object deleted ? thanks in advance. Yes. If there is no way that the first object can be accessed any more, then it will be deleted. The same thing happened to the string object return by raw_input() in your 3rd statement (which never had a name at all). [*1] My statement was an oversimplification. There are some cases where Python will return the same object such as interned objects and objects like None for which there is only ever a single instance in a Python program. -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On Dec 20, 2013, at 8:00 AM, Mark Lawrence wrote: > A good point. Shall I write a PEP asking for a language change which > requires that that stupid = sign is replaced by a keyword reading something > like thenameonthelefthandsideisassignedtheobjectontherighthandside ? Or a symbol like :=. As a former Smalltalker, I still miss this as the assignment operator, and the “gets” verbiage that went along with it. One said: x := 4 as in “x gets 4” I always got a kick out of the following paragraph from http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html. "1970 - Niklaus Wirth creates Pascal, a procedural language. Critics immediately denounce Pascal because it uses "x := x + y" syntax instead of the more familiar C-like "x = x + y". This criticism happens in spite of the fact that C has not yet been invented." -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.
Le vendredi 20 décembre 2013 18:52:44 UTC+1, Martin Schöön a écrit : > This thread hasn't been close to Python for while now and should > > be shut down. But, it is actually kind of interesting since you > > debate possible mechanisms behind the behaviour of my Windows box > > at work: "Not responding" is happening to me daily for any > > application including Microsoft's own Office Suite. I hoped it > > would go away when we moved from Vista to W7 but it didn't. > > > > In all fairness, our computers have both corporate and HP crapware > > installed so Microsoft may be innocent. > > > > Coming from many years of SUN Solaris experience I may be a bit > > spoiled when it comes to robustness :-) > > > > Now, let's leave this behind and spend time on Python -- something I > > with a formal programming education dating back to 1980 and F77 find > > fascinating. > The fact, that a main app window [%] falls in a "Ne répond pas", ("Not responding") state [*] with a mouse pointer becoming a "waiting pointer" is not so dramatic. As I pointed, despite this message in the title bar, the app works properly(?). The fact, that system becomes "unstable" is more critical. While being in that [*]-state, any attempt to work with the mouse, eg clicking on an another app window, leads to a [%] kill and to a msg box "Python has stopped working...". The Python process can be killed, it does not hurt the system. I'm observing this with the Qt-derivatives, PySide and PyQt4, and Python 3.3. Not with Python 3.2. >From where does it come from? No idea. I'm inclined to think, it's on the Qt side. Windows 7 pro jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: Copy a file like unix cp -a --reflink
Paulo da Silva writes: > Hi! > > Is there a way to copy a file the same as Unix command: > > cp -a --reflink src dest > > without invoking a shell command? I vaguely remember this was asked and answered some time ago and the answer was no, even just for -a. In fact, the python shutil module documentation starts with a warning to that effect. The --reflink stuff would be another thing altogether. More accurately, currently the only way would be to duplicate this functionality of cp in python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why Python is like C++
Serhiy Storchaka wrote: 20.12.13 16:19, Roy Smith написав(ла): http://xkcd.com/1306/ QBASIC$, not $QBASIC. Or just QB$. (Most BASICs of that era only regarded the first two characters as significant.) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Struggling with unittest discovery - how to structure my project test suite
On 12/20/2013 12:41 PM, Serhiy Storchaka wrote: 20.12.13 16:47, Paul Moore написав(ла): What's the best way of structuring my projects so that: It depends on your tradeoff between extra setup in the files and how much you type each time you run tests. 1. I can run all the tests easily on demand. I believe that if you copy Lib/idlelib/idle_test/__init__.py to tests/__main__.py and add import unittest; unittest.main() then python -m tests would run all your tests. Lib/idlelib/idle_test/README.py may help explain. 2. I can run just the functional or unit tests when needed. python -m unittest discover -s tests/functional python -m unittest discover tests/functional Ditto for __main__.py files in each, so python -m tests.unit (functional) will work. 3. I can run individual tests (or maybe just individual test modules, I don't have so many tests yet that I know how detailed I'll need to get!) without too much messing (and certainly without changing any source files!) python -m unittest discover -s tests/functional -p test_spam.py python -m unittest discover tests/functional -p test_spam.py python -m unittest discover tests/functional test_spam.py 'discover' is not needed for single files. For instance, python -m unittest idlelib.idle_test.test_calltips works for me. One can extend that to test cases and methods. python -m unittest idlelib.idle_test.test_calltips.Get_entityTest and python -m unittest idlelib.idle_test.test_calltips.Get_entityTest.test_bad_entity If you add to each test_xyz.py file if __name__ == '__main__': unittest.main(verbosity=2) # example of adding fixed option then python -m tests.unit.test_xyz will run the tests in that file. (So does F5 in an Idle editor, which is how I run individual test files while editing. I copy the boilerplate from README.txt or an existing test_xyz.py file.) -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 12/20/2013 10:16 AM, dec...@msn.com wrote: y = raw_input('Enter a number:') print type y y = float(raw_input('Enter a number:')) print type y I recommend starting with 3.3 unless your are forced to use 2.x. I also recommend trying code before posting it. I'm assuming that y is an object. The name 'y' is bound to an object. The second assignment rebinds 'y' to a different object. I'm also assuming that the second and the first y are different objects It depends on whether by 'y' you mean the name, which remains the same, or the object it is bound to, which changes. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
rusi wrote: Good idea. Only you were beaten to it by about 2 decades. More than 2, I think. Lisp: (setq x y) Algol: x := y Smalltalk: x <- y (where <- is a "left arrow" character) Cobol: MOVE X TO Y -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Struggling with unittest discovery - how to structure my project test suite
On Friday, 20 December 2013 17:41:40 UTC, Serhiy Storchaka wrote: > 20.12.13 16:47, Paul Moore написав(ла): > > > 1. I can run all the tests easily on demand. > > 2. I can run just the functional or unit tests when needed. > > python -m unittest discover -s tests/functional > python -m unittest discover tests/functional Hmm, I could have sworn I'd tried that. But you're absolutely right. Thanks, and sorry for the waste of bandwidth... Paul -- https://mail.python.org/mailman/listinfo/python-list
bytearray inconsistencies?
Quoting from http://docs.python.org/3/library/functions.html#bytearray "The bytearray type is a mutable sequence of integers in the range 0 <= x < 256." Quoting from http://docs.python.org/3/library/stdtypes.html#bytes-methods "Whenever a bytes or bytearray method needs to interpret the bytes as characters (e.g. the is...() methods, split(), strip()), the ASCII character set is assumed (text strings use Unicode semantics). Note - Using these ASCII based methods to manipulate binary data that is not stored in an ASCII based format may lead to data corruption. The search operations (in, count(), find(), index(), rfind() and rindex()) all accept both integers in the range 0 to 255 (inclusive) as well as bytes and byte array sequences. Changed in version 3.3: All of the search methods also accept an integer in the range 0 to 255 (inclusive) as their first argument." I don't understand why the docs talk about "a mutable sequence of integers" but then discuss "needs to interpret the bytes as characters". Further I don't understand why the changes done in 3.3 referred to above haven't also been applied to (say) the split method. If I can call find to look for a zero, why can't I split on it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: How to import Wave files into python?
On Wednesday, December 18, 2013 8:45:08 AM UTC-8, twilk...@gmail.com wrote: > How exactly do I import a .wav file and run it? > > also is it possible to run it inside a while loop if so or it just start > playing when its run? - Tom 14 QSound.play(wave_file) -- https://mail.python.org/mailman/listinfo/python-list
Re: bytearray inconsistencies?
On 12/20/13 8:06 PM, Mark Lawrence wrote: Quoting from http://docs.python.org/3/library/functions.html#bytearray "The bytearray type is a mutable sequence of integers in the range 0 <= x < 256." Quoting from http://docs.python.org/3/library/stdtypes.html#bytes-methods "Whenever a bytes or bytearray method needs to interpret the bytes as characters (e.g. the is...() methods, split(), strip()), the ASCII character set is assumed (text strings use Unicode semantics). Note - Using these ASCII based methods to manipulate binary data that is not stored in an ASCII based format may lead to data corruption. The search operations (in, count(), find(), index(), rfind() and rindex()) all accept both integers in the range 0 to 255 (inclusive) as well as bytes and byte array sequences. Changed in version 3.3: All of the search methods also accept an integer in the range 0 to 255 (inclusive) as their first argument." I don't understand why the docs talk about "a mutable sequence of integers" but then discuss "needs to interpret the bytes as characters". The split and strip methods work with whitespace when given no arguments. Bytes aren't whitespace. Characters can be, so the bytes need to be interpreted as characters. Likewise, the is* methods (isalnum, isalpha, isdigit, islower, isspace, istitle, isupper) all require characters, so the bytes must be interpreted. Further I don't understand why the changes done in 3.3 referred to above haven't also been applied to (say) the split method. If I can call find to look for a zero, why can't I split on it? I don't know the reason, but I would guess either no one considered it, or it was deemed unlikely to be useful. If you have a zero, you can split on it with: bytestring.split(bytes([0])), but that doesn't explain why find can take a simple zero, and split has to take a bytestring with a zero in it. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 12/20/13 6:58 PM, Dennis Lee Bieber wrote: On 20 Dec 2013 02:16:05 GMT, Steven D'Aprano declaimed the following: 2) Even for kernel developers, I believe that systems languages should be safe by default. You ought to have to explicitly disable (say) bounds checking in critical sections of code, rather than explicitly enable it. Or worse, have to program your own bounds checking -- especially if the compiler is permitted to silently disregard it if you make one tiny mistake. I wonder how BLISS falls into that... Have to read the rest of http://en.wikipedia.org/wiki/BLISS (while I had 22 years on VMS, it was mostly F77, a touch of F90, C, Pascal, and some DCL; but never used BLISS) Bliss is even lower-level than C. It made the too-consistent choice of having names mean the same thing on the left-hand side of an assignment as on the right-hand side. A name meant the address of a variable, so to access the value of a variable, you had to dereference it with the dot operator, much like the unary asterisk in C. C: a = b Bliss: a = .b C: a = a + 1 Bliss: a = .a + 1 C: a = *b Bliss: a = ..b C: a = &b Bliss: a = b It was far too common to forget the dots... -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: bytearray inconsistencies?
On 21/12/2013 01:58, Ned Batchelder wrote: On 12/20/13 8:06 PM, Mark Lawrence wrote: Quoting from http://docs.python.org/3/library/functions.html#bytearray "The bytearray type is a mutable sequence of integers in the range 0 <= x < 256." Quoting from http://docs.python.org/3/library/stdtypes.html#bytes-methods "Whenever a bytes or bytearray method needs to interpret the bytes as characters (e.g. the is...() methods, split(), strip()), the ASCII character set is assumed (text strings use Unicode semantics). Note - Using these ASCII based methods to manipulate binary data that is not stored in an ASCII based format may lead to data corruption. The search operations (in, count(), find(), index(), rfind() and rindex()) all accept both integers in the range 0 to 255 (inclusive) as well as bytes and byte array sequences. Changed in version 3.3: All of the search methods also accept an integer in the range 0 to 255 (inclusive) as their first argument." I don't understand why the docs talk about "a mutable sequence of integers" but then discuss "needs to interpret the bytes as characters". The split and strip methods work with whitespace when given no arguments. Bytes aren't whitespace. Characters can be, so the bytes need to be interpreted as characters. Likewise, the is* methods (isalnum, isalpha, isdigit, islower, isspace, istitle, isupper) all require characters, so the bytes must be interpreted. Further I don't understand why the changes done in 3.3 referred to above haven't also been applied to (say) the split method. If I can call find to look for a zero, why can't I split on it? I don't know the reason, but I would guess either no one considered it, or it was deemed unlikely to be useful. Explanation, or lack of it, here http://bugs.python.org/issue12170 If you have a zero, you can split on it with: bytestring.split(bytes([0])), but that doesn't explain why find can take a simple zero, and split has to take a bytestring with a zero in it. I now have working code as a result of the above paragraph, thanks for that :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Why Python is like C++
On 12/20/2013 02:44 PM, Gregory Ewing wrote: > Serhiy Storchaka wrote: >> 20.12.13 16:19, Roy Smith написав(ла): >> >>> http://xkcd.com/1306/ >> >> QBASIC$, not $QBASIC. > > Or just QB$. (Most BASICs of that era only regarded > the first two characters as significant.) Maybe BASIC's of the 70s. But Not QB. QuickBasic was a pretty impressive compiler in its day. Completely modern, structured language. And a pretty impressive IDE for its day that did some pretty slick source code navigation. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why Python is like C++
On 20/12/2013 14:19, Roy Smith wrote: http://xkcd.com/1306/ I believe that to be a very superficial like. They're unlike in that once C++ people have compiled their code they can head down to the pub, but Python people have to stay at work testing because the compiler hasn't caught all potential errors. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
sort(*, key=None, reverse=None)
The subject refers to the list sort method given here http://docs.python.org/3/library/stdtypes.html#list. I believe that the "*," bit is simply a typo, given that the docs also state "sort() accepts two arguments that can only be passed by keyword". Am I correct? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: sort(*, key=None, reverse=None)
On Fri, Dec 20, 2013 at 11:16 PM, Mark Lawrence wrote: > The subject refers to the list sort method given here > http://docs.python.org/3/library/stdtypes.html#list. I believe that the > "*," bit is simply a typo, given that the docs also state "sort() accepts > two arguments that can only be passed by keyword". Am I correct? It's good practice in technical writing to repeat yourself: once in the formal spec, and once in plain english. I don't see why this would be a typo. -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Re: sort(*, key=None, reverse=None)
On 21/12/2013 07:20, Devin Jeanpierre wrote: On Fri, Dec 20, 2013 at 11:16 PM, Mark Lawrence wrote: The subject refers to the list sort method given here http://docs.python.org/3/library/stdtypes.html#list. I believe that the "*," bit is simply a typo, given that the docs also state "sort() accepts two arguments that can only be passed by keyword". Am I correct? It's good practice in technical writing to repeat yourself: once in the formal spec, and once in plain english. I don't see why this would be a typo. -- Devin So what is it actually saying? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: sort(*, key=None, reverse=None)
On Sat, Dec 21, 2013 at 6:16 PM, Mark Lawrence wrote: > The subject refers to the list sort method given here > http://docs.python.org/3/library/stdtypes.html#list. I believe that the > "*," bit is simply a typo, given that the docs also state "sort() accepts > two arguments that can only be passed by keyword". Am I correct? The *, means that they're keyword-only arguments. It prevents you from passing them positionally. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: sort(*, key=None, reverse=None)
On Sat, Dec 21, 2013 at 6:24 PM, Mark Lawrence wrote: > On 21/12/2013 07:20, Devin Jeanpierre wrote: >> >> On Fri, Dec 20, 2013 at 11:16 PM, Mark Lawrence >> wrote: >>> >>> The subject refers to the list sort method given here >>> http://docs.python.org/3/library/stdtypes.html#list. I believe that the >>> "*," bit is simply a typo, given that the docs also state "sort() accepts >>> two arguments that can only be passed by keyword". Am I correct? >> >> >> It's good practice in technical writing to repeat yourself: once in >> the formal spec, and once in plain english. I don't see why this would >> be a typo. >> >> -- Devin >> > > So what is it actually saying? def func(x, y, *moreargs, foo, bar): pass Any positional args after x and y will go into moreargs, so foo and bar have to be specified by keywords. (And are mandatory, since I didn't default them.) If moreargs isn't given a name, then additional positional args are forbidden, but the requirements on foo and bar are the same. ChrisA -- https://mail.python.org/mailman/listinfo/python-list