Re: How to keep cookies when making http requests (Python 2.7)
Luca Cerone luca.cer...@gmail.com writes: ... Python has a module for cookie handling: cookielib (cookiejar in Python 3). urllib2 has a standard way to integrate with this module. However, I do not know the details (check the documentation for the modules). I have used cookielib externally to urllib2. It looks like this: from urllib2 import urlopen, Request from cookielib import CookieJar cookies = CookieJar() r = Request(...) cookies.add_cookie_header(r) # set the cookies R = urlopen(r, ...) # make the request cookies.extract_cookies(R, r) # remember the new cookies -- http://mail.python.org/mailman/listinfo/python-list
Any Django users in Reims (France) ?
Bonjour, Je cherche des dev Django dans la région de Reims (France) pour organiser des rencontres sympas et échanger sur notre plateforme préférée voire développer ensemble nos excellentes idées. A votre écoute, Fabrice -- http://mail.python.org/mailman/listinfo/python-list
Basic Python Query
Hi all, Please see the below code. class Test(threading.Thread): def StartThread(self): Lock = threading.Lock() self.start() class Test1(threading.Thread): def __init__(self): threading.Thread.__init__ ( self ) self.Lock = threading.Lock() self.start() if __name__ == '__main__': instance = Test() instance.StartThread() instance1= Test1() instance1.start() Please clarify the questions below with respect to above code 1.Difference between def StartThread(self) and def __init__(self): 2 instance = Test() ,when this is called ,the code flow goes inside the threading module ,But instance1= Test1() ,the code flow goes inside the class Test1 When we call the both classes in same way ,How does the flow is different for both. 3. Lets say self is passed explicitly for all the methods Like def method1(self) method2() def method2(self): method3() def method(self) method4() def method4(self) What does self holds in method4 ,Is it self argument from method1? Sorry i'm confused with self argument.Please clarify if its valid question. Best Regards, Chandan-- http://mail.python.org/mailman/listinfo/python-list
Re: Replace blanks with letter
Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program import random letters='abcdefg' blanks='_'*len(letters) print('type letters from a to g') print(blanks) for i in range(len(letters)): if letters[i] in input(): blanks = blanks[:i] + letters[i] + blanks[i+1:] print(blanks) If anyone could post an example of how to correctly code this, I would appreciate it. I can't seem to figure it out. I'll definitely heed Fabio's advice for future reference, but I don't think it's related to the problems I'm currently experiencing. If it is, and I'm just not getting it (most likely the case), please post an example of how to implement his code advice in doing what I wish to accomplish here. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to keep cookies when making http requests (Python 2.7)
I have used cookielib externally to urllib2. It looks like this: from urllib2 import urlopen, Request from cookielib import CookieJar cookies = CookieJar() r = Request(...) cookies.add_cookie_header(r) # set the cookies R = urlopen(r, ...) # make the request cookies.extract_cookies(R, r) # remember the new cookies Hi Dieter, thanks a lot for the help. I am sorry but your code is not very clear to me. It seems that you are setting some cookies, but I can't understand how you use the ones that the site sends to you when you perform the initial request. Have you tried this code to check if this work? If it works as intended can you explain a bit better what it does exactly? Thanks again! Luca -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
On Wed, 21 Aug 2013 14:50:20 +0800, chandan kumar wrote: [...] 1.Difference between def StartThread(self) and def __init__(self): __init__ is a special method called automatically by Python when you create an instance. StartThread is a method that the author of the code (perhaps you?) wrote themselves. It has no special meaning in Python, it will do whatever it is programmed to do, but only if you call it. 2 instance = Test() ,when this is called ,the code flow goes inside the threading module , But instance1= Test1() ,the code flow goes inside the class Test1 When we call the both classes in same way ,How does the flow is different for both. When Test() is called, a new Test instance is created, and the __init__ method is called, but the thread is not started. When you call Test1(), the __init___ method automatically starts the thread, because it includes the line self.start(). (Although, in the code you show, the indentation is wrong and the code will not work correctly. Please be more careful in the future about the indentation.) 3. Lets say self is passed explicitly for all the methods Like def method1(self) method2() That won't work, you need to say self.method2() def method2(self): method3() def method(self) method4() def method4(self) What does self holds in method4 ,Is it self argument from method1? Sorry i'm confused with self argument.Please clarify if its valid question. Yes, it is the same self all the way through. If you have ordinary functions: def f1(x): f2(x) def f2(y): f3(y) def f3(z): print z and you call f1(something), then the result will be to print something. Even though the argument name is different, the same argument is passed from one function to the next. Methods are exactly the same, except that the self argument is nearly always called self. When you have an instance, and you call one of its methods: instance = SomeClass() instance.method(extra, args) then Python automatically uses the instance as the self argument. This is equivalent to: SomeClass.method(instance, extra, args) # inside the method, self=instance except Python does it for you, instead of you needing to write it out in full like that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: refresing the edited python function
Thank you, But I wish if there was a foolproof reload with best regards, Sudheer - Original Message - From: Jean-Michel Pichavant jeanmic...@sequans.com To: Sudheer Joseph sudheer.jos...@yahoo.com Cc: python-list@python.org Sent: Tuesday, 20 August 2013 10:07 PM Subject: Re: refresing the edited python function - Original Message - Hi, I have been using ipython and ipython with qtconsole and working on a code with functions. Each time I make a modification in function I have to quit IPTHON console (in both with and with out qt console ) and reload the function freshly. If I need to see the changed I made in the function. I tried below options del function name import the module again by issuing from xxx.py import yy import xxx.py make changes reload(xxx.py) this works only if the the function in the code has same name as the code. But even this do not reflect the changes made by editing the code. So what is the standard way to update the function for further tests after an edit? with best regards, Sudheer Hi, My standard way ;) : 1/ create a file 2/ edit the code 3/ run ipython (with %pdb on) 4/ within ipython run myfile.py 5/ check / introspect /debug 6/ change the code 7/ exit ipython 8/ reenter ipython 9/ using the ipython shell history, reexecute the file (2 key press) and go back to 5/ I used to reload my objects, it's been useful until one time when I lost a lot of time because of some nasty side effect. In the end it's not worth it. Always quit the shell, always. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to keep cookies when making http requests (Python 2.7)
On 21 Aug 2013 09:22, Luca Cerone luca.cer...@gmail.com wrote: I have used cookielib externally to urllib2. It looks like this: from urllib2 import urlopen, Request from cookielib import CookieJar cookies = CookieJar() r = Request(...) cookies.add_cookie_header(r) # set the cookies R = urlopen(r, ...) # make the request cookies.extract_cookies(R, r) # remember the new cookies Hi Dieter, thanks a lot for the help. I am sorry but your code is not very clear to me. It seems that you are setting some cookies, but I can't understand how you use the ones that the site sends to you when you perform the initial request. This example does both. The cookie jar adds the cookies to the http request to be sent to the server, and updates the cookies from the response, if any were sent. It seems pretty clear, seeing that it has a lot of comments. The cookies from the site are thus in the cookie jar object after the call to extract_cookies() extracts them from the response. Have you tried this code to check if this work? If it works as intended can you explain a bit better what it does exactly? You should really test this yourself ;) Thanks again! Luca -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
Am 21.08.2013 08:50, schrieb chandan kumar: class Test(threading.Thread): def StartThread(self): Lock = threading.Lock() self.start() Inconsistently indented code, this is a killer for Python. Please read PEP8 and use four spaces! That said, there is never a need for deriving from the Thread class, you can also use it to run a function without that. That way is IMHO clearer because the threading.Thread instance is not the thread, just like a File instance is not a file. Both just represent handles for manipulating the actual thing. Further, you have a local variable called Lock here (should be lowercase, see PEP 8) that you don't use. This is either a bug you missed or at least code that you didn't trim in order to produce a minimal example. class Test1(threading.Thread): def __init__(self): threading.Thread.__init__ ( self ) Check out the super() syntax. 1.Difference between def StartThread(self) and def __init__(self): __init__ is a special function that gets called automatically. Search online for the documentation and or further explanations. 3. Lets say self is passed explicitly for all the methods Like def method1(self) method2() def method2(self): method3() def method(self) method4() def method4(self) What does self holds in method4 ,Is it self argument from method1? Sorry i'm confused with self argument. self is just a name like others, only that it is customarily used for the first parameter of memberfunctions, i.e. for the instance of the according class. That said, above seven lines don't really serve to illustrate anything, because they are far from valid Python code. I think before tackling threading, you should first go through some tutorials and documentation. I'd start with http://docs.python.org and/or do some online searches. Good luck! Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace blanks with letter
On Wed, Aug 21, 2013 at 5:49 PM, eschneide...@comcast.net wrote: Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program Some of us don't have time to just execute arbitrary code in some safe environment, so we'd REALLY rather you paste in the exception traceback (if it's throwing one), or explain what it ought to be doing that it isn't doing, or in whatever other way show what the problems actually are. Remember, what's obvious to you isn't obvious to us; what you see as an obvious problem might actually be correct behaviour, so without knowing your expectations, we can't pinpoint the trouble. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Matrix sort
Hi I have a matrix of numbers representing the nodal points as follows: Element No.Nodes 1 1 2 3 4 2 5 6 7 8 3 2 3 9 10 ... ... x 9 10 11 12 ... so this is a matrix of numbers 4 x n Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 and x are neighbours (they share nodes 9 and 10). I want to sort the matrix in such a way all the elements are sequentially arranged. How could I script it? can any one help me? Thanks! Vijayendra -- http://mail.python.org/mailman/listinfo/python-list
How to change scrollbar color in pygtk ?
Hi, I Tried the below code, the color is not reflected, Am i missing something? #add description box beside test cases testCaseDescWindow = gtk.ScrolledWindow() testCaseDescWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) testCaseDescWindow.get_vscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F')) testCaseDescWindow.get_hscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F')) Thanks, Norah Jones -- http://mail.python.org/mailman/listinfo/python-list
Re: default python os x
On 20Aug2013 09:01, Uwe Rangs uwe.ra...@fernuni-hagen.de wrote: | Ah, I see. Thank you! Please don't top post. Thanks. | On 2013-08-20 05:39:56 +, Steven D'Aprano said: | alias python1.5='env -u PYTHONSTARTUP python1.5' I should point out that -u is a GNU env feature. It is not portable, and in particular OSX env does not have it. A shell function can do the same though: py20() { ( unset PYTHONSTARTUP exec python2.0 ${1+$@} ) } I've said py20 instead of python2.0 primarily because bash is a bit... picky about function names and rejected the .. Cheers, -- Cameron Simpson c...@zip.com.au But pessimism IS realism! - D.L.Bahr -- http://mail.python.org/mailman/listinfo/python-list
Re: Matrix sort
On 21 August 2013 10:24, vijayendramunik...@gmail.com wrote: Hi I have a matrix of numbers representing the nodal points as follows: Element No.Nodes 1 1 2 3 4 2 5 6 7 8 3 2 3 9 10 ... ... x 9 10 11 12 ... so this is a matrix of numbers 4 x n Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 and x are neighbours (they share nodes 9 and 10). I want to sort the matrix in such a way all the elements are sequentially arranged. How could I script it? can any one help me? I think you want a topological sort algorithm. See here: http://en.wikipedia.org/wiki/Topological_sorting Before that though you'll want to preprocess your matrix into a data structure that allows you to easily find the elements adjacent to any given element. A list of lists is one approach: graph = [ [3], # nodes adjacent to element 1 [], # element 2 [1, x], # element 3 ... [3] # element x ] Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace blanks with letter
eschneide...@comcast.net wrote: Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program import random letters='abcdefg' blanks='_'*len(letters) print('type letters from a to g') print(blanks) for i in range(len(letters)): if letters[i] in input(): blanks = blanks[:i] + letters[i] + blanks[i+1:] print(blanks) If anyone could post an example of how to correctly code this, I would appreciate it. I can't seem to figure it out. I'll definitely heed Fabio's advice for future reference, but I don't think it's related to the problems I'm currently experiencing. If it is, and I'm just not getting it (most likely the case), please post an example of how to implement his code advice in doing what I wish to accomplish here. Nowhere have you told us just what the homework assignment was. Depending on the goal, this could be fixed in various ways. As it stands, you are asking the user 7 times to type in the letters from a to g. So long as he responds each time the same way, it'll gradually fill in the letters from left to right, and end up with all seven showing. In fact, it'll do that even if the user just types the particular single letter you're asking for. So in my last response below, I typed a string that didn't have all 7, but it did have a g, so that was good enough. davea@think2:~/temppython$ python3.3 eric.py type letters from a to g ___ abcdefg a__ abcdefg ab_ abcdefg abc abcdefg abcd___ abcdefg abcde__ agcdbfe abcdef_ aggecca abcdefg davea@think2:~/temppython$ Maybe the problem is that you don't tell the user whether he has succeeded or not. To tell that, just stick a test at the end, outside the for-loop. if blanks == letters: print(Good job) else: print(You lose, run again, and guess what I wanted) -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Create an App with Python Win $5000
Hi all, JotForm just announced its developer contest with their newly released API with a grand prize of $5000 to the best app and $500 for other categories. The API library can be used with Python so you can create endless apps with it. The deadline for the contest is September 24, 2013. Apply to the contest from http://developers.jotform.com/competition/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace blanks with letter
In 89146bb1-fb60-4746-93e2-6cb59cfbc...@googlegroups.com eschneide...@comcast.net writes: Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program No, they're not clear. We can see what the code does, obviously, but we don't know what it's *supposed* to do. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
I wonder if I would be able to collect data from such page using Python
Hi, I am totally new to Python. I noticed that there are many videos showing how to collect data from Python, but I am not sure if I would be able to accomplish my goal using Python so I can start learning. Here is the example of the target page: http://and.medianewsonline.com/hello.html In this example, there are 10 articles. What I exactly need is to do the following: 1- Collect the article title, date, source, and contents. 2- I need to be able to export the final results to excel or a database client. That is, I need to have all of those specified in step 1 in one row, while each of them saved in separate column. For example: Title1Date1 Source1 Contents1 Title2Date2 Source2 Contents2 I appreciate any advise regarding my case. Thanks Regards// -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
On Wed, Aug 21, 2013 at 10:55 AM, Comment Holder commenthol...@gmail.com wrote: Hi, I am totally new to Python. I noticed that there are many videos showing how to collect data from Python, but I am not sure if I would be able to accomplish my goal using Python so I can start learning. Here is the example of the target page: http://and.medianewsonline.com/hello.html In this example, there are 10 articles. What I exactly need is to do the following: 1- Collect the article title, date, source, and contents. 2- I need to be able to export the final results to excel or a database client. That is, I need to have all of those specified in step 1 in one row, while each of them saved in separate column. For example: Title1Date1 Source1 Contents1 Title2Date2 Source2 Contents2 I appreciate any advise regarding my case. Thanks Regards// -- http://mail.python.org/mailman/listinfo/python-list I'm guessing that you are not only new to Python, but that you haven't much experience in writing computer programs at all. So, you need to do that. There is a good tutorial on the python site, and lots of links to other resources. then do this: 1. write code to access the page you require. The Requests module can help with that 2. write code to select the data you want. The BeautifulSoup module is excellent for this 3. write code to save your data in comma separated value format. 4. import to excel or wherever Now, go off and write the code. When you get stuck, copy and paste the portion of the code that is giving you problems, along with the traceback. You can also get help at the python-tutor mailing list -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
Many thanks Joel, You are right to some extent. I come from Finance background, but I am very familiar with what could be referred to as non-native languages such as Matlab, VBA,.. actually, I have developed couple of complete programs. I have asked this question, because I am a little worried about the structure of this particular page, as there are no specific defined classes. I know how powerful Python is, but I wonder if it could do the job with this particular page. Again, many thanks Joel, I appreciate your guidance. All Best// -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
On Wed, Aug 21, 2013 at 11:44 AM, Comment Holder commenthol...@gmail.com wrote: Many thanks Joel, You are right to some extent. I come from Finance background, but I am very familiar with what could be referred to as non-native languages such as Matlab, VBA,.. actually, I have developed couple of complete programs. I have asked this question, because I am a little worried about the structure of this particular page, as there are no specific defined classes. I know how powerful Python is, but I wonder if it could do the job with this particular page. Again, many thanks Joel, I appreciate your guidance. All Best// -- http://mail.python.org/mailman/listinfo/python-list Your biggest hurdle will be to get proficient with python. Give yourself a weekend with a good tutorial. You won't be very skilled, but you will get the gist of things. Also, google Beautiful Soup. You need the latest version. Its v4 I think. They have a GREAT tutorial. Spend a few hours with it and you will see your way to get the data you want from your web pages. Since you gave a sample web page, I am guessing that you need to log in to the site for 'real data'. For that, you need to really understand stuff that you might not. At any rate, study the Requests Module documentation. Python comes with urllib, and urllib2 that cover the same ground, but Requests is a lot simpler to understand -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Unpickling data with classes from dynamic modules
Dear list, I have a system in which I load modules dynamically every now and then (that is, creating a module with types.ModuleType, compiling the code for the module and then executing it in the module with exec()), and where I would wish to be able to have classes in those modules containing classes that could pickled, and then unpickled again. The problem with that, currently, is of course two-fold: The dynamically loaded module may not be loaded at the time when the unpickling takes place, but even if it were, it isn't registered in sys.modules, so the unpickler can't find it either way. And, of course, that is detected already when pickling. Is there any way to fix this, at all? I considered trying to create subclasses of the pickler and unpickler that pickle a reference to a module loader and data for the particular module along with a class that comes from such a module, by overriding Pickler.save_global and Unpickler.load_global. Unfortunately, however, those functions aren't part of the public interface and can't be overridden when the C-pickle module is used instead (which, obviously, is what normally happens). Is there any way around this without having to modify the pickle module itself? -- Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
A data transformation framework. A presentation inviting commentary.
Hi all, In an effort to do some serious cleaning up of a hopelessly cluttered working environment, I developed a modular data transformation system that pretty much stands. I am very pleased with it. I expect huge time savings. I would share it, if had a sense that there is an interest out there and would appreciate comments. Here's a description. I named the module TX: The nucleus of the TX system is a Transformer class, a wrapper for any kind of transformation functionality. The Transformer takes input as calling argument and returns it transformed. This design allows the assembly of transformation chains, either nesting calls or better, using the class Chain, derived from 'Transformer' and 'list'. A Chain consists of a sequence of Transformers and is functionally equivalent to an individual Transformer. A high degree of modularity results: Chains nest. Another consequence is that many transformation tasks can be handled with a relatively modest library of a few basic prefabricated Transformers from which many different Chains can be assembled on the fly. A custom Transformer to bridge an eventual gap is quickly written and tested, because the task likely is trivial. A good analogy of the TX methodology is a road map with towns scattered all over it and highways connecting them. To get from any town to any other one is a simple matter of hopping the towns in between. The TX equivalent of the towns are data formats, the equivalent of the highways are TX Transformers. They are not so much thought of in terms of what they do than in terms of the formats they take and give. Designing a library of Transformers is essentially a matter of establishing a collection of standard data formats. First the towns, then the highways. A feature of the TX Transformer is that it retains both its input and output. This makes a Chain a breeze to build progressively, link by link, and also makes debugging easy: If a Chain doesn't work, Chain.show () reveals the failing link as the first one that has no output. It can be replaced with a corrected instance, as one would replace a blown fuse. Running the Chain again without input makes it have another try. Parameter passing runs on a track that is completely separate from the payload track. Parameters can be set in order to configure a Chain prior to running it, or can be sent at runtime by individual Transformers to its siblings and their progeny. Parameters are keyed and get picked up by those Chain links whose set of pre-defined keys includes the parameter's key. Unintended pick-ups with coincidentally shared keys for unrelated parameters can be prevented by addressing parameters to individual Translators. Below an application example. Five custom classes at the end exemplify the pattern. I join the post also as attachment, in case some auto-line-wrap messes up this text. Commentary welcome Frederic An example of use: Download historic stock quotes from Yahoo Finance for a given range of dates and a list of symbols, delete a column and add three, insert the data in a MySQL table. Also write them to temporary files in tabular form for verification. make_quotes_writer () returns a custom transformation tree. run_quotes () makes such a tree, sets it on a given time range and runs it on a list of symbols. (Since Yahoo publishes the data for downloading, I presume it's okay to do it this way. This is a demo of TX, however, and should not be misconstrued as an encouragement to violate any publisher's terms of service.) import TX, yahoo_historic_quotes as yhq def make_quotes_writer (): Visualizer = TX.Chain ( yhq.percent (), TX.Table_Maker (has_header = True), TX.Table_Writer (), name = 'Visualizer' ) To_DB = TX.Chain (yhq.header_stripper(), TX.DB_Writer(table_name = 'quotes'), name = 'To DB') To_File = TX.Chain (Visualizer, TX.File_Writer (), name = 'To File') Splitter = TX.Splitter (To_DB, To_File, name = 'Splitter') Quotes = TX.Chain ( yhq.yahoo_quotes (), TX.CSV_To_List (delimiter = ','), TX.Numerizer (), yhq.wiggle_and_trend (), yhq.symbol (), Splitter, name = 'Quotes' ) return Quotes Quotes = make_quotes_writer () Quotes.show_tree() Quotes Quotes[0] - Yahoo Quotes Quotes[1] - CSV To List Quotes[2] - Numerizer Quotes[3] - Wiggle and Trend Quotes[4] - Symbol Quotes[5] - Splitter Quotes[5][0] - To DB Quotes[5][0][0] - Header Stripper Quotes[5][0][1] - DB Writer Quotes[5][1] - To File Quotes[5][1][0] - Visualizer Quotes[5][1][0][0] - Percent Quotes[5][1][0][1] - Table Maker Quotes[5][1][0][2] - Table Writer Quotes[5][1][1] - File Writer def run_quotes (symbols, from_date = '1970-01-01', to_date = '2099-12-31'): '''Downloads historic
Re: refresing the edited python function
Dave Angel da...@davea.name writes: Seems to me your problem is with ipython's IDE, not with Python. Python requires you to rerun your application when making most changes to code. But it doesn't say anything about restarting a console, whatever that is in this context. I use Komodo IDE when i want an IDE functionality, and never restart Komodo, over hours of work. IPython's IDE just works the way alex23 described. -- Piet van Oostrum p...@vanoostrum.org WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation unpythonic?
On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of the public interface, It may wish to be notified when its name changes, and so have a name property. The subclass may want to use a variable called _name for some other purpose. (maybe name isn't the best example). Examples often look pathological when you simplify out the bit that makes them make sense. -- Random832 -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal asmbans...@gmail.com wrote: Currently the documentation download includes a lot of things but PEPs are not its part. I wanted to suggest that PEPs should be included in the download. They are very much relevant to Python. The PEPs are kinda like the specs that Python is built from, rather than being end-user documentation; certainly most, if not all, are unnecessary to most use of Python. There's really no point downloading a whole pile of rejected PEPs as part of the crucial user-facing docs. Also, how many people actually depend on the downloadable documentation, rather than simply reading things online? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
Dear Joel, Many thanks for your help - I think I shall start with this way and see how it goes. My concerns were if the task can be accomplished with Python, and from your posts, I guess it can - so I shall give it a try :). Again, thanks a lot all best// -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
On Wed, Aug 21, 2013 at 1:41 PM, Comment Holder commenthol...@gmail.com wrote: Dear Joel, Many thanks for your help - I think I shall start with this way and see how it goes. My concerns were if the task can be accomplished with Python, and from your posts, I guess it can - so I shall give it a try :). Again, thanks a lot all best// -- http://mail.python.org/mailman/listinfo/python-list You're welcome. One thought popped into my mind. Since the site seems to be from the Wall Street Journal, you may want to look into whether they have an api for searching and retrieving articles. If they do, this would be simpler and probably safer than parsing web pages. From time to time, websites change their layout, which would probably break your program. However APIs are more stable good luck to you -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Wed, Aug 21, 2013, at 13:32, Chris Angelico wrote: On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal asmbans...@gmail.com wrote: Currently the documentation download includes a lot of things but PEPs are not its part. I wanted to suggest that PEPs should be included in the download. They are very much relevant to Python. The PEPs are kinda like the specs that Python is built from, rather than being end-user documentation; certainly most, if not all, are unnecessary to most use of Python. There's really no point downloading a whole pile of rejected PEPs as part of the crucial user-facing docs. Also, how many people actually depend on the downloadable documentation, rather than simply reading things online? If you've taken your laptop to somewhere there's no wi-fi, it's nice to have offline help. I think, though, that if there's any useful information that can be obtained by reading accepted PEPs but not the documentation, or if things are explained less clearly than in the PEPs, that's a bug in the documentation, and should be remedied by adding to the documentation. -- http://mail.python.org/mailman/listinfo/python-list
utcoffset v. _utcoffset
Consider this little Python script: import dateutil.parser import pytz x = dateutil.parser.parse(2013-08-16 23:00:00+01:00) localtz = pytz.timezone(America/Chicago) y = localtz.normalize(x) When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this traceback: Traceback (most recent call last): File /home/skipm/tmp/localtzex.py, line 8, in module y = localtz.normalize(x) File /opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py, line 233, in normalize offset = dt.tzinfo._utcoffset AttributeError: 'tzoffset' object has no attribute '_utcoffset' Looking at the tzinfo attribute, I see that it has utcoffset, but not _utcoffset. I realize those are the latest, most up-to-datest versions of all three elements. I'm having trouble updating dateutil and pytz on my Mac at home (stuck on even older versions). Can someone with newer versions of dateutil and pytz see if this problem is still present? Thx, Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Wed, Aug 21, 2013 at 1:55 PM, random...@fastmail.us wrote: I think, though, that if there's any useful information that can be obtained by reading accepted PEPs but not the documentation, or if things are explained less clearly than in the PEPs, that's a bug in the documentation, and should be remedied by adding to the documentation. Personally, the only PEPs I've used as reference material as PEP 8 (the Python Style Guide), and PEP 249 (the Python Database API Specification v2.0). If I recall correctly, one of the database adapters I used basically said that they were PEP 249 compliant, and didn't have much documentation beyond that. It seems to me that adding the PEPs to the compiled documentation would be a good thing. They are at least as useful as the Language Reference or the Embedding and Extending Python sections that are already included. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: refresing the edited python function
On Wed, Aug 21, 2013 at 4:26 PM, Sudheer Joseph sudheer.jos...@yahoo.com wrote: Thank you, But I wish if there was a foolproof reload with best regards, Sudheer There isn't, any more than there's a foolproof way to prevent top-posting. Some languages are designed to handle code reload; others simply aren't. Python is one of the latter. And even when you're using a language like Pike, you really have to design your application around code reload; so it's a feature of specific apps (like MUDs) that will be running for years on end without restarting, rather than something that you want all the time. Otherwise, you run the risk of having internal data structures and code out of sync - and if you're not keeping anything significant from the previous run, then why are you reloading code instead of restarting the app? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Wed, Aug 21, 2013, at 14:15, Jerry Hill wrote: Personally, the only PEPs I've used as reference material as PEP 8 (the Python Style Guide), and PEP 249 (the Python Database API Specification v2.0). If I recall correctly, one of the database adapters I used basically said that they were PEP 249 compliant, and didn't have much documentation beyond that. Maybe there should be documentation for PEP 249 and other such API Specifications in the main documentation tree, in the same way that .NET documents interfaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Thu, Aug 22, 2013 at 4:15 AM, Jerry Hill malaclyp...@gmail.com wrote: On Wed, Aug 21, 2013 at 1:55 PM, random...@fastmail.us wrote: I think, though, that if there's any useful information that can be obtained by reading accepted PEPs but not the documentation, or if things are explained less clearly than in the PEPs, that's a bug in the documentation, and should be remedied by adding to the documentation. Personally, the only PEPs I've used as reference material as PEP 8 (the Python Style Guide), and PEP 249 (the Python Database API Specification v2.0). If I recall correctly, one of the database adapters I used basically said that they were PEP 249 compliant, and didn't have much documentation beyond that. It seems to me that adding the PEPs to the compiled documentation would be a good thing. They are at least as useful as the Language Reference or the Embedding and Extending Python sections that are already included. Ah, yes, there are a few that would be good. But I don't really see that all the internally bits (PEP 393, anyone?) and rejected proposals (PEP 315) need to be in the download. I wouldn't expect the full set of RFCs to be included with the docs for the socket module, so I equally don't expect the PEPs to be included. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
On 21.08.2013 11:11, Ulrich Eckhardt wrote: That said, there is never a need for deriving from the Thread class, you can also use it to run a function without that. That way is IMHO clearer because the threading.Thread instance is not the thread, just like a File instance is not a file. Both just represent handles for manipulating the actual thing. Huh? That I find most curious. I *always* derive from threading.Thread and really like the way that thread setup works (instanciate Thread handle, call start). Very intuitive, never had the problems with clarity that you mentioned. Could you elaborate on your suggestion? I don't seem to quite get it I'm afraid. Best regards, Johannes -- Wo hattest Du das Beben nochmal GENAU vorhergesagt? Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa hidbv3$om2$1...@speranza.aioe.org -- http://mail.python.org/mailman/listinfo/python-list
Re: A data transformation framework. A presentation inviting commentary.
On Thu, Aug 22, 2013 at 2:29 AM, F.R. anthra.nor...@bluewin.ch wrote: The nucleus of the TX system is a Transformer class, a wrapper for any kind of transformation functionality. The Transformer takes input as calling argument and returns it transformed. Not to put too much of a damper on your concept, but it's seeming a little over-engineered. Your description of a Transformer sounds to me like simply... a function. It takes input, it returns something. Why the heavy class-based interface? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
On 8/21/2013 1:52 PM, Joel Goldstick wrote: On Wed, Aug 21, 2013 at 1:41 PM, Comment Holder commenthol...@gmail.com wrote: Many thanks for your help - I think I shall start with this way and see how it goes. My concerns were if the task can be accomplished with Python, and from your posts, I guess it can - so I shall give it a try :). CM: You still seem a bit doubtful. If you are wondering why no one else has answered, it is because Joel has given you a really good answer that cannot be beat without writing your code for you. You're welcome. One thought popped into my mind. Since the site seems to be from the Wall Street Journal, you may want to look into whether they have an api for searching and retrieving articles. If they do, this would be simpler and probably safer than parsing web pages. From time to time, websites change their layout, which would probably break your program. However APIs are more stable Including this suggestion, which I did not think of. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: A data transformation framework. A presentation inviting commentary.
On 8/21/2013 12:29 PM, F.R. wrote: Hi all, In an effort to do some serious cleaning up of a hopelessly cluttered working environment, I developed a modular data transformation system that pretty much stands. I am very pleased with it. I expect huge time savings. I would share it, if had a sense that there is an interest out there and would appreciate comments. Here's a description. I named the module TX: You appear to have developed a framework for creating data flow networks. Others exists, including Python itself and things built on top of Python, like yours. I am not familiar with others built on Python, but I would not be surprised if your occupies its own niche. It is easy enough to share on PyPI. The nucleus of the TX system is a Transformer class, a wrapper for any kind of transformation functionality. The Transformer takes input as calling argument and returns it transformed. This design allows the assembly of transformation chains, either nesting calls or better, using the class Chain, derived from 'Transformer' and 'list'. Python 3 is built around iterables and iterators. Iterables generalize the notion of list to any structure that can be sequentially accessed. A collection can be either concrete, existing all at once in some memory, or abstract, with members created as needed. One can think of there being two types of iterator. One merely presents the items of a collection one at a time. The other transforms items one at a time. The advantage of 'lazy' collections' is that they scale up much better to processing, say, a billion items. If your framework keeps the input list and all intermediate lists, as you seem to say, then your framework is memory constrained. Python (mostly) shifted from list to iterables as the common data interchange type partly for this reason. You are right that keeping data around can help debugging. Without that, each iterator must be properly tested if its operation is not transparent. A Chain consists of a sequence of Transformers and is functionally equivalent to an individual Transformer. A high degree of modularity results: Chains nest. Because iterators are also iterables, they nest. A transformer iterator does not care if its input is a concrete non-iterator iterable, a source iterator representing an abstract collection, or another transformer. Another consequence is that many transformation tasks can be handled with a relatively modest library of a few basic prefabricated Transformers from which many different Chains can be assembled on the fly. This is precisely the idea of the itertool modules. I suspect that itertools.tee is equivalent to Tx.split (from the deleted code). Application areas need more specialized iterators. There are many in various stdlib modules. A custom Transformer to bridge an eventual gap is quickly written and tested, because the task likely is trivial. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: make elements of a list twice or more.
On 08/07/2013 01:50 AM, liuerfire Wang wrote: Sorry for the title which didn't make clear. Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are different type). Now I wanna generate a new list as [b, b, a, a, c, c]. If you don't care about the order, you can do: x = x + x -- http://mail.python.org/mailman/listinfo/python-list
Arpex Capital seleciona: Desenvolvedor Python (MongoDB) / SP
Arpex Capital seleciona para uma de suas empresas: Desenvolvedor Python (MongoDB) Objetivo geral da Posição: Desenvolver software estável e de primeira linha, que será incorporado à plataforma de WiFi mais moderna atualmente. Responsabilidades: escrever software que rodará tanto no backend (Python) quanto no frontend (HTML5). Pré-requisitos: - Conhecimento em Python, MongoDB - Cloud computing, BigData - Pensamento lógico e analítico - Capacidade de absorver tecnologias novas de forma constante Deveres: - Escrever software sólido em Python Formação: Irrelevante (não cobramos) Local de Trabalho: São Paulo/SP A empresa oferece remuneração compatível com o mercado + Benefícios. Os interessados deverão enviar o CV para kgar...@arpexcapital.com.br , mencionando no assunto Desenvolvedor Python (MongoDB). -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On 8/21/2013 1:32 PM, Chris Angelico wrote: On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal asmbans...@gmail.com wrote: Currently the documentation download includes a lot of things but PEPs are not its part. I wanted to suggest that PEPs should be included in the download. They are very much relevant to Python. The PEPs are kinda like the specs that Python is built from, rather than being end-user documentation; certainly most, if not all, are unnecessary to most use of Python. There's really no point downloading a whole pile of rejected PEPs as part of the crucial user-facing docs. The manuals are intended to document current reality. Accepted PEPs document plans, often minus details. They do not get updated to reflect the initial implementation, let alone subsequent changes. Thus even There are a few chapters in the manual that reference a PEP, either because the details are though to be too esoteric for the manual or becuase no one has yet gotten around to rewriting the material for the manual. (In the latter case, a patch should be welcome.) So there might be a reason to include a '(Highly) Selected PEPs' heading to the main page. PEP 8 might be a candidate, though it was originally intended as an internal style guide for the stdlib only. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
RE: Unpickling data with classes from dynamic modules
Fredrik Tolf wrote: Dear list, I have a system in which I load modules dynamically every now and then (that is, creating a module with types.ModuleType, compiling the code for the module and then executing it in the module with exec()), and where I would wish to be able to have classes in those modules containing classes that could pickled, and then unpickled again. The problem with that, currently, is of course two-fold: The dynamically loaded module may not be loaded at the time when the unpickling takes place, but even if it were, it isn't registered in sys.modules, so the unpickler can't find it either way. And, of course, that is detected already when pickling. Is there any way to fix this, at all? I considered trying to create subclasses of the pickler and unpickler that pickle a reference to a module loader and data for the particular module along with a class that comes from such a module, by overriding Pickler.save_global and Unpickler.load_global. Unfortunately, however, those functions aren't part of the public interface and can't be overridden when the C-pickle module is used instead (which, obviously, is what normally happens). Is there any way around this without having to modify the pickle module itself? -- Fredrik Tolf -- I believe rather than subclassing the pickler, you are expected to change the behavior from within the class via __getstate__ and __setstate__. http://docs.python.org/2/library/pickle.html#object.__getstate__ Although, for your use case (loading unknown classes) the section on pickle and extension types may be more appropriate. http://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types Maybe all you need to add is implementation for obj.__reduce__ ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: utcoffset v. _utcoffset
On 8/21/2013 2:05 PM, Skip Montanaro wrote: Consider this little Python script: import dateutil.parser import pytz Neither of these are stdlib modules, so I cannot run this. x = dateutil.parser.parse(2013-08-16 23:00:00+01:00) localtz = pytz.timezone(America/Chicago) y = localtz.normalize(x) When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this traceback: Traceback (most recent call last): File /home/skipm/tmp/localtzex.py, line 8, in module y = localtz.normalize(x) File /opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py, line 233, in normalize offset = dt.tzinfo._utcoffset AttributeError: 'tzoffset' object has no attribute '_utcoffset' Looking at the tzinfo attribute, I see that it has utcoffset, but not _utcoffset. I realize those are the latest, most up-to-datest versions of all three elements. I'm having trouble updating dateutil and pytz on my Mac at home (stuck on even older versions). Can someone with newer versions of dateutil and pytz see if this problem is still present? -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: utcoffset v. _utcoffset
In article CANc-5UwRWF343mmOeCJhKj6KaU1m4=qgxhrb3pxv1x5_od-...@mail.gmail.com, Skip Montanaro s...@python.org wrote: Consider this little Python script: import dateutil.parser import pytz x = dateutil.parser.parse(2013-08-16 23:00:00+01:00) localtz = pytz.timezone(America/Chicago) y = localtz.normalize(x) When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this traceback: Traceback (most recent call last): File /home/skipm/tmp/localtzex.py, line 8, in module y = localtz.normalize(x) File /opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py, line 233, in normalize offset = dt.tzinfo._utcoffset AttributeError: 'tzoffset' object has no attribute '_utcoffset' Looking at the tzinfo attribute, I see that it has utcoffset, but not _utcoffset. I realize those are the latest, most up-to-datest versions of all three elements. I'm having trouble updating dateutil and pytz on my Mac at home (stuck on even older versions). Can someone with newer versions of dateutil and pytz see if this problem is still present? I believe the problem is that you are using them incorrectly. IAMNADatetimeExpert, but I think you are trying to normalize a non-tz-aware datetime object returned from dateutil.parser.parse. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw_input with readline in a daemon thread makes terminal text disappear
Hi all, This is an old thread, but I'm having the same behavior in my terminal when I run some code but kill the process in the terminal (Ctrl-C). The code has two prime suspects (from a simple google search): 1. Creates ssh port forward via the subprocess module (http://unix.stackexchange.com/questions/4740/screen-remote-login-failure-an d-disappearing-text) 2. Using the getpass module (raw_input?) Calling $ reset brings back the disappearing text, so I'm just wondering if this issue has been addressed and if so, what should I be doing that I'm not. Thank you, Dave W. Response to post: http://mail.python.org/pipermail/python-list/2009-October/554784.html I'm getting input for a program while it's running by using raw_input in a loop in separate thread. This works except for the inconvenience of not having a command history or the use of backspace etc. That can be solved by loading the readline module; however, it results in a loss of visible access to the terminal when the program ends: nothing is echoed to the screen and the history is invisible (although it is there - hitting return executes whatever should be there normally). The only way to get it back is to close the terminal and open a new one. Here is minimal code that reproduces the problem (python 2.5 on Linux): from threading import Thread import readline get_input = Thread(target=raw_input) get_input.setDaemon(True) get_input.start() If the thread is not set to daemon mode, there is no such problem (don't know why this makes a difference), but in the real program, it needs to be a daemon or it hangs the exit waiting for more input. Any suggestions appreciated. Thanks, John -- http://mail.python.org/mailman/listinfo/python-list
python3-sqlalchemy and debian repo
Dear all, I want to use sqlalchemy library, When i use apt-cashe search sqlalchemy , get the following result(part of result): /// python-sqlalchemy - SQL toolkit and Object Relational Mapper for Python python-sqlalchemy-doc - documentation for the SQLAlchemy Python library python-sqlalchemy-ext - SQL toolkit and Object Relational Mapper for Python - C extension python3-sqlalchemy - SQL toolkit and Object Relational Mapper for Python 3 Question: I want to use python 3, So i didn't doc and ext suffix for sqlalchemy compatiable with python 3. The given suffix removed in python 3 or merged in python3-sqlalchemy package? --mohsen -- http://mail.python.org/mailman/listinfo/python-list
Re: NodeTransformer: how to remove nodes?
Thanks Chris and Peter. I already went further along. No more issues so far. 2013/8/19 Peter Otten __pete...@web.de Tobias Müller wrote: I'm facing an issue with NodeTransformer, a tool used for Python AST manipulations. Last week I posted on stackoverflow.com, but there are no responses yet. Maybe someone reading the mailing list can have a look and leave me a response here or over there? http://stackoverflow.com/questions/18275662/python-nodetransformer-how-to- remove-nodes As Chris says, you are overriding too much of the generic behaviour. Here is a working demo: import ast class MyTransformer(ast.NodeTransformer): def visit_For(self, node): For nodes: replace with nothing print(removing a For node) return None source = l = [0, 1, 2, 3] total = 0 for i in l: total += i print(total) transformer = MyTransformer() module = ast.parse(source) transformer.visit(module) codeobj = compile(module, 'string', 'exec') exec(codeobj) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: utcoffset v. _utcoffset
Skip Montanaro wrote: Consider this little Python script: import dateutil.parser import pytz x = dateutil.parser.parse(2013-08-16 23:00:00+01:00) localtz = pytz.timezone(America/Chicago) y = localtz.normalize(x) When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this traceback: Traceback (most recent call last): File /home/skipm/tmp/localtzex.py, line 8, in module y = localtz.normalize(x) File /opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py, line 233, in normalize offset = dt.tzinfo._utcoffset AttributeError: 'tzoffset' object has no attribute '_utcoffset' Looking at the tzinfo attribute, I see that it has utcoffset, but not _utcoffset. I realize those are the latest, most up-to-datest versions of all three elements. I'm having trouble updating dateutil and pytz on my Mac at home (stuck on even older versions). Can someone with newer versions of dateutil and pytz see if this problem is still present? Thx, Skip -- Using Python 2.6, dateutil 1.5, pytz 2013b Snipped from the documentation of pytz via help(localtz.normalize) ''' Correct the timezone information on the given datetime If date arithmetic crosses DST boundaries, the tzinfo is not magically adjusted. This method normalizes the tzinfo to the correct one. ''' Going from +1 to +6 will not cross the DST boundary. The documentation for localtz.normalize (in pytz 2013b) has a sample of what to do if it does cross DST which seems to boil down to using datetime.astimezone() and then localtz.normalize() if your date arithmetic crosses DST. import dateutil.parser import pytz x = dateutil.parser.parse(2013-08-16 23:00:00+01:00) localtz = pytz.timezone(America/Chicago) x.astimezone( localtz ) datetime.datetime(2013, 8, 16, 17, 0, tzinfo=DstTzInfo 'America/Chicago' CDT-1 day, 19:00:00 DST) ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw_input with readline in a daemon thread makes terminal text disappear
On Wed, Aug 21, 2013, at 12:42, David M. Welch wrote: Hi all, This is an old thread, but I'm having the same behavior in my terminal when I run some code but kill the process in the terminal (Ctrl-C). The code has two prime suspects (from a simple google search): 1. Creates ssh port forward via the subprocess module (http://unix.stackexchange.com/questions/4740/screen-remote-login-failure-an d-disappearing-text) 2. Using the getpass module (raw_input?) Calling $ reset brings back the disappearing text, so I'm just wondering if this issue has been addressed and if so, what should I be doing that I'm not. Do you understand how tty modes (in particular, echo vs non-echo mode) work? What you've got is two different pieces of code (I think running readline in two threads qualifies) fighting over the tty mode, and probably one of them is turning echo mode off and then either never restoring it because of how the program exits, or it gets into the other's idea of the original mode. Why does your program design require input to be handled in a thread other than the main thread? -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation unpythonic?
On Aug 21, 2013 10:53 AM, random...@fastmail.us wrote: On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of the public interface, It may wish to be notified when its name changes, and so have a name property. The example as given has no such property, and regardless of whether it is a property or an attribute the public API should just be called name. The subclass may want to use a variable called _name for some other purpose. (maybe name isn't the best example). Probably not a good idea for multiple reasons if the base class already has something called name. On Aug 21, 2013 10:53 AM, random...@fastmail.us wrote: On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of the public interface, It may wish to be notified when its name changes, and so have a name property. The subclass may want to use a variable called _name for some other purpose. (maybe name isn't the best example). Examples often look pathological when you simplify out the bit that makes them make sense. -- Random832 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
On 21 Aug 2013 20:07, Johannes Bauer dfnsonfsdu...@gmx.de wrote: On 21.08.2013 11:11, Ulrich Eckhardt wrote: That said, there is never a need for deriving from the Thread class, you can also use it to run a function without that. That way is IMHO clearer because the threading.Thread instance is not the thread, just like a File instance is not a file. Both just represent handles for manipulating the actual thing. Huh? That I find most curious. I *always* derive from threading.Thread and really like the way that thread setup works (instanciate Thread handle, call start). Very intuitive, never had the problems with clarity that you mentioned. Could you elaborate on your suggestion? I don't seem to quite get it I'm afraid. Best regards, Johannes I cannot tell whether you are trolling or are just new to this, but you don't always have to use threads. You use threads when you need multiple parts of your program running concurrently. Don't inherit Thread if all you are doing is a simple object with state, nor if your program does not need concurrency. -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
On 8/21/13 6:50 PM, Fábio Santos wrote: On 21 Aug 2013 20:07, Johannes Bauer dfnsonfsdu...@gmx.de mailto:dfnsonfsdu...@gmx.de wrote: On 21.08.2013 11:11, Ulrich Eckhardt wrote: That said, there is never a need for deriving from the Thread class, you can also use it to run a function without that. That way is IMHO clearer because the threading.Thread instance is not the thread, just like a File instance is not a file. Both just represent handles for manipulating the actual thing. Huh? That I find most curious. I *always* derive from threading.Thread and really like the way that thread setup works (instanciate Thread handle, call start). Very intuitive, never had the problems with clarity that you mentioned. Could you elaborate on your suggestion? I don't seem to quite get it I'm afraid. Best regards, Johannes I cannot tell whether you are trolling or are just new to this, but you don't always have to use threads. You use threads when you need multiple parts of your program running concurrently. Don't inherit Thread if all you are doing is a simple object with state, nor if your program does not need concurrency. I think it is safe to assume that Johannes meant, when I use threads, I never do it the way you suggested, I always derive from threading.Thread. --Ned. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation unpythonic?
On Wed, 21 Aug 2013 12:52:06 -0400, random832 wrote: On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of the public interface, It may wish to be notified when its name changes, and so have a name property. The subclass may want to use a variable called _name for some other purpose. (maybe name isn't the best example). Such a name property would be a public interface, and so a Good Thing. However, my toy example was of a case where something *obviously useful* was being left out of the public interface. If it were a public property, it wouldn't be the case that it were left out, would it? Examples often look pathological when you simplify out the bit that makes them make sense. Naturally :-) I did call this a toy example. Nevertheless, in the Real World, data hiding can sometimes be a bit of a religion. Not all cases where people try various tricks and hacks to gain access to private and protected members are specious. The whole Java getter and setter philosophy is based on the idea that everything, even the most innocuous data attribute, ought to be private, with a computed getter and setter Just In Case some day in the future you want to wrap access in code. In Python, you can turn an attribute into a computed property with no change to the public interface. In Java, you can't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Using PyQT with QT Designer
I'm learning Python and I have a problem. I've asked the question everywhere and no one helps me, so I'm hoping someone here will. I am making a program that shows album covers and you click on the album cover in the top window. In the bottom window, the list of songs appear and you can click the individual song to play it. It's going to be a media player for children. I'm thinking I'll be able to use a dict and have the album as the key and the list of songs as the value to accomplish this. Right now, I'm just using my picture directory to try and get the basic layout right. I designed a form in QT Designer: http://i.imgur.com/Wrp1zHW.png Here is my gui file I got from running pyuic4 on the ui file: # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'window.ui' # # Created by: PyQt4 UI code generator 4.9.6 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8(MainWindow)) MainWindow.resize(800, 600) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8(centralwidget)) self.tableWidget = QtGui.QTableWidget(self.centralwidget) self.tableWidget.setGeometry(QtCore.QRect(70, 20, 661, 381)) self.tableWidget.setObjectName(_fromUtf8(tableWidget)) self.tableWidget.setColumnCount(0) self.tableWidget.setRowCount(0) self.listWidget = QtGui.QListWidget(self.centralwidget) self.listWidget.setGeometry(QtCore.QRect(70, 400, 661, 181)) self.listWidget.setObjectName(_fromUtf8(listWidget)) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate(MainWindow, MainWindow, None)) Now, according to websites I read, I should just have to add the following to my program to get it to use the form: from window import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None, **kwargs): super(MainWindow, self).__init__(parent) self.setupUi(self) and here is my program: from PyQt4.QtCore import * from PyQt4.QtGui import * from window import Ui_MainWindow THUMBNAIL_SIZE = 128 SPACING= 10 IMAGES_PER_ROW = 5 class TableWidget(QTableWidget): def __init__(self, parent=None, **kwargs): QTableWidget.__init__(self, parent, **kwargs) self.setIconSize(QSize(128,128)) self.setColumnCount(IMAGES_PER_ROW) self.setGridStyle(Qt.NoPen) # Set the default column width and hide the header self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING) self.verticalHeader().hide() # Set the default row height and hide the header self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING) self.horizontalHeader().hide() # Set the table width to show all images without horizontal scrolling self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2)) def addPicture(self, row, col, picturePath): item=QTableWidgetItem() # Scale the image by either height or width and then 'crop' it to the # desired size, this prevents distortion of the image. p=QPixmap(picturePath) if p.height()p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE) else: p=p.scaledToHeight(THUMBNAIL_SIZE) p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE) item.setIcon(QIcon(p)) self.setItem(row,col,item) class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None, **kwargs): super(MainWindow, self).__init__(parent) self.setupUi(self) centralWidget=QWidget(self) l=QVBoxLayout(centralWidget) self.tableWidget=TableWidget(self) l.addWidget(self.tableWidget) self.setCentralWidget(centralWidget) picturesPath=QDesktopServices.storageLocation(QDesktopServices.PicturesLocation) pictureDir=QDir(picturesPath) pictures=pictureDir.entryList(['*.jpg','*.png','*.gif']) rowCount=len(pictures)//IMAGES_PER_ROW if len(pictures)%IMAGES_PER_ROW: rowCount+=1
Python and mysql 3 tier programming
Hi all, I'm now to the list so apologies if I don't always follow the local protocol. My problem is the interface between python and mysql using a three tier model. First, some background: System Debian Wheezy Linux Python 2.7 Mysql 5.5.31 Apache Server I am somewhat conversant with html, css, SQL, mysql, Apache and Debian Linux. Actually I have been using Debian for over 10 year. I spent over 5 year, prior to retirement, programming database based applications in Foxpro. I can also struggle through Java Script. I am just starting to use python. I've started with development of a rather complicated document archiving system with about 5 different levels of users and over 100 years of documents. photos, etc. The database setup has gone smoothly and other than one trial web page I'm leaving that for later. Finally to the problem. Where does python start and mysql stored procedures stop and visa versa. I'm trying to stick to a 3 tier philosophy but am having trouble figuring out where the dividing line is between the two packages. Further python seems to like cursor tables a lot and Oracles Mysql 5.5 discourages their use. Are they talking about the same thing. My problem is mostly with the basic architecture of the system. I think I will be able to figure out the code. Also, any comments on the use of the Django framework for this project. Thanks in advance Gary R. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding problem in python
If you use Arabic frequently on your system, I suggest to change your windows system locale from Region and Language in control panel (Administrative tab) and set to Arabic. -- http://mail.python.org/mailman/listinfo/python-list
RE: Unpickling data with classes from dynamic modules
On Wed, 21 Aug 2013, Prasad, Ramit wrote: Fredrik Tolf wrote: [...] I considered trying to create subclasses of the pickler and unpickler that pickle a reference to a module loader and data for the particular module along with a class that comes from such a module, by overriding Pickler.save_global and Unpickler.load_global. Unfortunately, however, those functions aren't part of the public interface and can't be overridden when the C-pickle module is used instead (which, obviously, is what normally happens). [...] I believe rather than subclassing the pickler, you are expected to change the behavior from within the class via __getstate__ and __setstate__. Well, that clearly wouldn't work, since that still assumes the module can be found. Maybe all you need to add is implementation for obj.__reduce__ That would certainly work, and I guess I could perhaps use it as a work-around, but that would mean I'd have to mark every single such class as such in some way or another. What I'm looking for is a solution that could make them picklable transparently, just like normal. -- Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On 22Aug2013 03:32, Chris Angelico ros...@gmail.com wrote: | Also, how many people actually depend on the downloadable | documentation, rather than simply reading things online? I do. It is outstandingly faster, and works when one is offline; I always have a local copy of a 2.x and 3.x documentation set as desktop icons, ready for instant opening. I agree I rarely need the PEPs unless I want to look up something unusual. Cheers, -- Cameron Simpson c...@zip.com.au I need your clothes, your boots, and your motorcycle. - Arnold Schwarzenegger, Terminator 2 -- http://mail.python.org/mailman/listinfo/python-list
Re: I wonder if I would be able to collect data from such page using Python
Comment Holder commenthol...@gmail.com writes: Hi, I am totally new to Python. I noticed that there are many videos showing how to collect data from Python, but I am not sure if I would be able to accomplish my goal using Python so I can start learning. Here is the example of the target page: http://and.medianewsonline.com/hello.html In this example, there are 10 articles. What I exactly need is to do the following: 1- Collect the article title, date, source, and contents. 2- I need to be able to export the final results to excel or a database client. That is, I need to have all of those specified in step 1 in one row, while each of them saved in separate column. For example: Title1Date1 Source1 Contents1 Title2Date2 Source2 Contents2 I appreciate any advise regarding my case. Thanks Regards// Here is an attempt for you. It uses BeatifulSoup 4. It is written in Python 3.3, so if you want to use Python 2.x you will have to make some small changes, like from urllib import urlopen and probably something with the print statements. The formatting in columns is left as an exercise for you. I wonder how you would want that with multiparagraph contents. from bs4 import BeautifulSoup from urllib.request import urlopen URL = http://and.medianewsonline.com/hello.html; html = urlopen(URL).read() soup = BeautifulSoup(html) arts = soup.find_all('div', class_='articleHeader') for art in arts: name = art.contents[0].string.strip() print(name) artbody = art.find_next_sibling('div', class_='article enArticle') titlenode = artbody.find_next('div', id='hd') title = titlenode.get_text().strip() print(Title: {0}.format(title)) srcnode = titlenode.find_next('a') while srcnode.parent.get('class') == ['author']: srcnode=srcnode.find_next('a') source = srcnode.string srcnode = srcnode.parent date = srcnode.find_previous_sibling('div').string print(Date: {0}.format(date)) print(Source: {0}.format(source)) cont = srcnode.find_next_siblings('p', class_='articleParagraph enarticleParagraph') contents = '\n'.join([c.get_text() for c in cont]) print(Contents: {0}.format(contents)) -- Piet van Oostrum p...@vanoostrum.org WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list
pydoc vs. non-def'd methods
Greetings, I'm hava a class in which there are two equally useful names for one method. Consider this design (there are other approaches, but that's not what my question is about): class Spam1: def eggs(self): '''Return the Meaning of Life.''' return 42 ham = eggs help(Spam1) shows that ham = eggs(self), which isn't all bad, but it could be better. help(Spam1.ham) shows the help for eggs; I know why, but this could be better as well. And in any case, eggs looks somehow better than ham, because eggs has its own def statement and ham doesn't. Now consider this design, designed to overcome the previous issues: class Spam2: def _private(self): '''Return the Meaning of Life.''' return 42 ham = _private eggs = _private Now help(Spam2.ham) and help(Spam2.eggs) show the same thing, but help(Spam2) hides _private and its docstring and shows that ham and eggs both call _private. That's no good. I can expose _private (e.g., by renaming it to public), but that defeats the purpose of making it private in the first place. I can go ahead and define ham to invoke eggs, but then I have to duplicate the docstring, and it's not being-hit-on-the-head obvious that ham and eggs are simply synonyms for the same functionality. I could put the documentation at the class level, but then it doesn't show up as part of help(Spam2.eggs) or help(Spam1.ham). So is there a clean way to define SpamN such that help(SpamN), help(SpamN.ham), and help(SpamN.eggs) all do the Right Thing, and the symmetry of ham and eggs is perfectly obvious to the most casual observer? Thanks, Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
in 704175 20130822 010625 Ned Batchelder n...@nedbatchelder.com wrote: This is a multi-part message in MIME format. Please post in plain text, not HTML. -- http://mail.python.org/mailman/listinfo/python-list
Running a command line program and reading the result as it runs
Greetings all. I'm using Python 2.7 under Windows and am trying to run a command line program and process the programs output as it is running. A number of web searches have indicated that the following code would work. import subprocess p = subprocess.Popen(D:\Python\Python27\Scripts\pip.exe list -o, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True, shell=False) for line in p.stdout: print line When I use this code I can see that the Popen works, any code between the Popen and the for will run straight away, but as soon as it gets to the for and tries to read p.stdout the code blocks until the command line program completes, then all of the lines are returned. Does anyone know how to get the results of the program without it blocking? Thanks, Ian Simcock. -- http://mail.python.org/mailman/listinfo/python-list
[issue812369] module shutdown procedure based on GC
Changes by Antoine Pitrou pit...@free.fr: -- superseder: module shutdown procedure based on GC - Stop purging modules which are garbage collected before shutdown ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue812369 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18790] incorrect text in argparse add_help example
Changes by Michael Bikovitsky moshe.b...@gmail.com: -- keywords: +patch Added file: http://bugs.python.org/file31393/doc_fix.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18790 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18790] incorrect text in argparse add_help example
Changes by Michael Bikovitsky moshe.b...@gmail.com: -- nosy: +Michael.Bikovitsky ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18790 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18794] select.devpoll objects have no close() method
Charles-François Natali added the comment: Just to be explicit (there are typos in Victor's original messages): it's about select.devpoll, for Solaris-derivatives with /dev/poll, and not for select.poll, based on poll() syscall. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18794 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16853] add a Selector to the select module
Charles-François Natali added the comment: I've lost track -- who is waiting for whom? I reviewed the patch selector-12.diff and received zero response AFAICT. (Maybe the email from Rietveld didn't make it?) I was on vacation, and then had to cope with many emails :-) I'll update the patch with your comments soon. Maybe the main issue is that I would prefer if the selector classes were in a separate module (selectors.py) than the low-level select/poll/etc. calls. I think it makes sense if the selectors module *only* defines the high level classes and not the messy low-level stuff, since an app shouldn't be using both at the same time. I agree with Antoine (i.e. I think select is OK), but if it really bothers you, I can change it. I just don't want to do it twice :-) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16853 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18792] test_ftplib timeouts
Charles-François Natali added the comment: Some ftplib tests sometimes time out. Seem they seem to try to connect to localhost (rather than 127.0.0.1), I was wondering if this could be a DNS issue and if we should resolve localhost in advance like Charles-François did for some other tests (or simply hardcode 127.0.0.1, actually). If it only happens on Windows = 7 buildbots, then it's likely a consequence of this: http://serverfault.com/questions/4689/windows-7-localhost-name-resolution-is-handled-within-dns-itself-why Apparently, since Windows 7, localhost doesn't appear in the hosts file anymore: so, depending on your DNS resolver settings, this could perfectly explain such timeouts (assuming it's not a firewall issue). Hard-cording 127.0.0.1 for this test should be OK, because the server setup explicitly binds an AF_INET socket. We'll probably have to check the rest of the test suite for similar issues. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18792 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18797] Don't needlessly change refcounts of dummy objects for sets
New submission from Raymond Hettinger: AFAICT, there is no reason for sets to incref and decref dummy objects. The dummy object address is used as placeholders in the hash table but it is never accessed by set the logic. As long the one reference is held at the time the dummy object is created, nothing further is served by the increfs and decrefs. I can take them out entirely or use ifdefs to keep them for debug builds. Does anyone know of any issues? -- components: Interpreter Core files: no_refcnt_dummy1.diff keywords: patch messages: 195751 nosy: rhettinger priority: normal severity: normal status: open title: Don't needlessly change refcounts of dummy objects for sets type: performance versions: Python 3.4 Added file: http://bugs.python.org/file31394/no_refcnt_dummy1.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18797 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18792] test_ftplib timeouts
Antoine Pitrou added the comment: Hard-cording 127.0.0.1 for this test should be OK, because the server setup explicitly binds an AF_INET socket. We'll probably have to check the rest of the test suite for similar issues. Ok, let's do it! -- keywords: +easy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18792 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18797] Don't needlessly change refcounts of dummy objects for sets
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18797 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18797] Don't needlessly change refcounts of dummy objects for sets
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +Mark.Shannon, tim.peters ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18797 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18797] Don't needlessly change refcounts of dummy objects for sets
Antoine Pitrou added the comment: I can't think of any counter-indication but I think we shouldn't distinguish between debug and non-debug mode. That way the debug hooks can check that the refcounting optimization is right. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18797 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18792] test_ftplib timeouts
Antoine Pitrou added the comment: Here is a patch for default. -- keywords: +patch Added file: http://bugs.python.org/file31395/support_host.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18792 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18712] Pure Python operator.index doesn't match the C version.
Changes by Serhiy Storchaka storch...@gmail.com: -- dependencies: +PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18793] occasional test_multiprocessing_forkserver failure on FreeBSD 10.0
koobs added the comment: Antoine, did you see: #18762 ? It references the samee failures on 9.x as well. Do you want to close this as a dupe, or maintain separate issues for each OS? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18793 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18793] occasional test_multiprocessing_forkserver failure on FreeBSD 10.0
Antoine Pitrou added the comment: Ha, you're right, we can close this one as a duplicate. -- superseder: - error in test_multiprocessing_forkserver ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18793 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18794] select.devpoll objects have no close() method
STINNER Victor added the comment: Just to be explicit (there are typos in Victor's original messages): it's about select.devpoll, for Solaris-derivatives with /dev/poll, and not for select.poll, based on poll() syscall. Oops sorry, yes, I'm talking about select.devpoll, its structure has a int fd_devpoll; field: typedef struct { PyObject_HEAD int fd_devpoll; int max_n_fds; int n_fds; struct pollfd *fds; } devpollObject; -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18794 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14971] (unittest) loadTestsFromName does not work on method with a decorator
Michael Foord added the comment: Cool, thanks! -- assignee: - michael.foord ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14971 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)
Serhiy Storchaka added the comment: Yet some nitpicks. Currently the code of _PyLong_FromNbInt() is inlined and the do_decref flag is used to prevent needless change refcounts of int objects (see also issue18797). In proposed patch common code is extracted into the _PyLong_FromNbInt() function and int objects increfed and decrefed. Doesn't it affect a performance? PyLong_As* functions used in arguments parsing in a lot of builtins and their .performance is important. If the patch slowdowns PyLong_As* functions we perhaps should check PyLong_CheckExact() before calling _PyLong_FromNbInt() and use the do_decref flag. In general the idea and the patch LGTM. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17576 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16853] add a Selector to the select module
STINNER Victor added the comment: I like the idea of renaming select to _select, and add Lib/select.py for the high-level wrapper (Selector). In my opinion, adding a module just for 5 classes is overkill. Selector classes are a very thin abstraction over the low-level objects. A new module can be justified for something more evolved, something like an event loop with callbacks and a scheduler, something like the PEP 3156 (tulip) :-) This issue is for code written in Python. Is it a similar issue for code written in C? internal_select_ex() of Modules/socketmodule.c and check_socket_and_wait_for_timeout() of Modules/_ssl.c uses poll() and select(). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16853 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18794] select.devpoll objects have no close() method
Changes by Serhiy Storchaka storch...@gmail.com: -- nosy: +serhiy.storchaka stage: - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18794 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18713] Enable surrogateescape on stdin and stdout when appropriate
R. David Murray added the comment: I think the essential use case is using a python program in a unix pipeline. I'm very sympathetic to that use case, despite my unease. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18713 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18795] pstats - allow stats sorting by cumulative time per call and total time per call
R. David Murray added the comment: I believe the module already supports sorting by time and cumulative time (determining the top consumers of cpu is a major part of the point of the profile module, after all). What exactly is the change that you are proposing? If you post a diff instead of a modified copy of the module it would be easier to see what you are proposing. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18795 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18795] pstats - allow stats sorting by cumulative time per call and total time per call
Alexandre Dias added the comment: It does support sorting by total time and cumulative time spent on a function, but not by the time per each call of that function. I've uploaded a diff of the patch. -Alexandre -- versions: +Python 3.4 -Python 2.7 Added file: http://bugs.python.org/file31396/pstats-diff-issue18795.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18795 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)
Serhiy Storchaka added the comment: On PyPy 1.8.0 operator.index(True) returns 1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17576 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18792] test_ftplib timeouts
Charles-François Natali added the comment: Changing support.HOST from 'localhost' to '127.0.0.1' means that on dual-stack hosts (I don't think the test suite would run on IPv6-only hosts anyway), the tests will now always use IPv4, whereas they are currently using either IPv6 or IPv4 addresses depending on the host's name resolution settings. For example, on a RHEL6 box: socket.getaddrinfo('localhost', 0) [(10, 1, 6, '', ('::1', 0, 0, 0)), (10, 2, 17, '', ('::1', 0, 0, 0)), (10, 3, 0, '', ('::1', 0, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 0)), (2, 2, 17, '', ('127.0.0.1', 0)), (2, 3, 0, '', ('127.0.0.1', 0))] So on this host, 'localhost' resolves to '::1'. I think it would be better to have support.HOST set to socket.getaddrinfo('localhost', 0)[0][4][0] (sic), so that the test will use the preferred protocol on the target host, and also that IPv6 is also tested in tests which don't explicitely use '::1'. But this means that we should have an support.HOSTv4 for tests that explicitly rely on IPv4, e.g. test_ftplib. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18792 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18795] pstats - allow stats sorting by cumulative time per call and total time per call
R. David Murray added the comment: It would be clearer, I think, to call it average time. I must admit to not being sure why that is useful. I'm also worried there might be backward compatibility issues with changing the ordering of the data structure. If new fields are going to be added they should probably be added at the end. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18795 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18794] select.devpoll objects have no close() method
STINNER Victor added the comment: This all sounds fine to fix without waiting for anything else -- can you attach a patch here? I opened the issue as a reminder for me. Here is a patch. * Add close() and fileno() methods and a closed attribute (property) to devpoll object * Document closed attribute of epoll and kqueue objects * Add tests on closed object for devpoll, epoll and kqueue. There was no test for devpoll, epoll nor kqueue :-( select.poll is still not tested. We should add much more tests, especially tests checking than a fd becomes ready for each implementation. We may develop these tests using #16853 ? I ran test_select on Linux, so I only checked the epoll unit test. The closed attribute of epoll and kqueue objects should also be documented in Python 2.7 and 3.3. -- keywords: +patch Added file: http://bugs.python.org/file31397/devpoll_close.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18794 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18798] Typo and unused variables in test fcntl
New submission from Vajrasky Kok: Typo in line 11: # Skip test if no fnctl module. Unused variables rv in test_fcntl_file_descriptor method. Attached the patch to clean up the test. -- components: Tests files: fix_typo_unused_variables_in_test_fcntl.patch keywords: patch messages: 195768 nosy: vajrasky priority: normal severity: normal status: open title: Typo and unused variables in test fcntl versions: Python 3.4 Added file: http://bugs.python.org/file31398/fix_typo_unused_variables_in_test_fcntl.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18798 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18713] Enable surrogateescape on stdin and stdout when appropriate
STINNER Victor added the comment: Currently, Python 3 fails miserabily when it gets a non-ASCII character from stdin or when it tries to write a byte encoded as a Unicode surrogate to stdout. It works fine when OS data can be decoded from and encoded to the locale encoding. Example on Linux with UTF-8 data and UTF-8 locale encoding: $ mkdir test $ cd test $ touch héhé.txt $ ls héhé.txt $ python3 -c 'import os; print(, .join(os.listdir()))' héhé.txt $ echo héhé|python3 -c 'import sys; sys.stdout.write(sys.stdin.read())'|cat héhé It fails miserabily when OS data cannot be decoded from or encoded to the locale encoding. Example on Linux with UTF-8 data and ASCII locale encoding: $ mkdir test $ cd test $ touch héhé.txt $ export LANG= # switch to ASCII locale encoding $ ls h??h??.txt $ python3 -c 'import os; print(, .join(os.listdir()))' Traceback (most recent call last): File string, line 1, in module UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128) $ echo héhé|LANG= python3 -c 'import sys; sys.stdout.write(sys.stdin.read())'|cat Traceback (most recent call last): File string, line 1, in module File /home/vstinner/prog/python/default/Lib/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 1: ordinal not in range(128) The ls output is not the expected héhé string, but it is an issue with the console output, not the ls program. ls does just write raw bytes to stdout: $ ls|hexdump -C 68 c3 a9 68 c3 a9 2e 74 78 74 0a |h..h...txt.| 000b (héhé encoded to UTF-8 gives b'h\xc3\xa9h\xc3\xa9') I agree that we can do something to improve the situation on standard streams, but only on standard streams. It is already possible to workaround the issue by forcing the surrogateescape error handler on stdout: $ LANG= PYTHONIOENCODING=utf-8:surrogateescape python3 -c 'import os; print(, .join(os.listdir()))' héhé.txt Something similar can be done in Python. For example, test.support.regrtest reopens sys.stdout to set the error handle to backslashreplace. Extract of the replace_stdout() function: sys.stdout = open(stdout.fileno(), 'w', encoding=sys.stdout.encoding, errors=backslashreplace, closefd=False, newline='\n') -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18713 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18792] test_ftplib timeouts
Antoine Pitrou added the comment: Changing support.HOST from 'localhost' to '127.0.0.1' means that on dual-stack hosts (I don't think the test suite would run on IPv6-only hosts anyway), the tests will now always use IPv4, whereas they are currently using either IPv6 or IPv4 addresses depending on the host's name resolution settings. That would only be true if the server we are contacting happens to listen on both IPv6 and IPv4, right? I don't think we have such a situation in the test suite. Clients can use create_connection() for transparent support of IPv6 and IPv4, but servers have to choose a family when creating their socket. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18792 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18794] select.devpoll objects have no close() method
Serhiy Storchaka added the comment: poll, devpoll, epoll and kqueue are tested in test_poll.py, test_devpoll.py, test_epoll.py and test_kqueue.py test files. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18794 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)
Serhiy Storchaka added the comment: And yet one nitpick. For int subclasses which doesn't overload the __int__ method the patch calls default int.__int__ which creates a copy of int object. This is redundant in PyLong_As* functions because they only extract C int value and drop Python int object. So we can use int subclass object itself as good as int object. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17576 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18738] String formatting (% and str.format) issues with Enum
Serhiy Storchaka added the comment: print(member) %s % member {}.format(member) Would you seriously use either of those last two in either the debugger or the command line? Yes, of course. When you need debug output from function or loop inners. for ...: ... print('stage1(%s) = [%s:%s] %s' % (i, start, stop, result)) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18738 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18747] Re-seed OpenSSL's PRNG after fork
Roundup Robot added the comment: New changeset 8e1194c39bed by Christian Heimes in branch '3.3': Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork. http://hg.python.org/cpython/rev/8e1194c39bed New changeset 49e23a3adf26 by Christian Heimes in branch 'default': Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork. http://hg.python.org/cpython/rev/49e23a3adf26 New changeset 2e6aa6c29be2 by Christian Heimes in branch '2.7': Issue #18747: Re-seed OpenSSL's pseudo-random number generator after fork. http://hg.python.org/cpython/rev/2e6aa6c29be2 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18747 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18743] References to non-existant StringIO module
Changes by Serhiy Storchaka storch...@gmail.com: -- stage: commit review - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18743 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18738] String formatting (% and str.format) issues with Enum
Serhiy Storchaka added the comment: I'm proposing to split this issue on two issues. One for C-style formatting (I guess everyone agree that '%i' % int-like object should return decimal representation of its numerical value) and other for format() which is more questionable. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18738 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17916] Provide dis.Bytecode based equivalent of dis.distb
Claudiu.Popa added the comment: Here's a basic patch, using a classmethod. It doesn't support the full distb API (if the traceback is not given, try to retrieve the last one), because Bytecode.from_tb() looks pretty weird. -- keywords: +patch nosy: +Claudiu.Popa Added file: http://bugs.python.org/file31399/dis.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17916 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18747] Re-seed OpenSSL's PRNG after fork
Christian Heimes added the comment: I have taken care of Antoine's and Victor's reviews. The fix has landed in Python 2.7, 3.3 and 3.4. What about 2.6, 3.1 and 3.2? After all it's a security fix (although I don't consider its severity as high). -- nosy: +barry, benjamin.peterson, georg.brandl stage: patch review - commit review versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18747 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com