===== Soft Skills Training In Chennai ======
Ayus Technologies offers Dot net training in chennai,java/j2ee training in chennai,SEO training in chennai,web designing training in chennai,soft skills training in chennai,Software Testing training in chennai. http://www.ayustechnologies.com/ More Information contact Mr, Jana 9080140107 -- http://mail.python.org/mailman/listinfo/python-list
Re: [web] Long-running process: FCGI? SCGI? WSGI?
Gilles nos...@nospam.com writes: To write a long-running web application, I'd like to some feedback about which option to choose. Apparently, the choice boilds down to this: - FastCGI - SCGI - WSGI It seems like FCGI and SCGI are language-neutral, while WSGI is Python-specific. Besides that, how to make an informed choice about which option to choose? Obviously, this depends on your environment. Some hosters, web servers, applications may directly support one interface and not others. If you control your whole environment, I would look for a newer approach. I do not know SCGI but I know that WSGI is fairly recent. This means that during its design, FastCGI was already known and not deemed to be sufficient. Thus, you can expect more features (more modularisation, in this case) in WSGI. -- http://mail.python.org/mailman/listinfo/python-list
Dynamically scheduling Cron Jobs for Python Scripts.
I have a web scrapper script which run every day at 0100 hrs using cron Job over a shell account. Now what I am looking for is to re run the same script. 1 The script goes online to scrape some data including a schedule time for my meeting. I want to re run the script at that schedule time to send me a email. How can I do that? Plz Help -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On Thu, 06 Sep 2012 00:34:56 +, Antoine Pitrou wrote: Chris Angelico rosuav at gmail.com writes: On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy tjreedy at udel.edu wrote: io.open depends on a function the returns an open file descriptor. opener exposes that dependency so it can be replaced. I skimmed the bug report comments but didn't find an answer to this: Why not just monkey-patch? When a module function calls on a support function and you want to change that support function's behaviour, isn't monkey-patching the most usual? Monkey-patching globals is not thread-safe: other threads will see your modification, which is risky and fragile. Isn't that assuming that you don't intend the other threads to see the modification? If I have two functions in my module that call open, and I monkey-patch the global (module-level) name open to intercept that call, I don't see that there is more risk of breakage just because one function is called from a thread. Obviously monkey-patching the builtin module itself is much riskier, because it doesn't just effect code in my module, it affects *everything*. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: On 9/5/2012 8:48 AM, Ramchandra Apte wrote: and a==True should be automatically changed into memory comparison. I have no idea what that means. I interpret this as meaning that a == True should be special-cased by the interpreter as a is True instead of calling a.__eq__. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On 6 September 2012 16:34, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 06 Sep 2012 00:34:56 +, Antoine Pitrou wrote: Monkey-patching globals is not thread-safe: other threads will see your modification, which is risky and fragile. Isn't that assuming that you don't intend the other threads to see the modification? If I have two functions in my module that call open, and I monkey-patch the global (module-level) name open to intercept that call, I don't see that there is more risk of breakage just because one function is called from a thread. Obviously monkey-patching the builtin module itself is much riskier, because it doesn't just effect code in my module, it affects *everything*. It's not as though the option to monkey-patch has been taken away. But hopefully there is now less of a need for it. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Thursday, 6 September 2012 12:14:19 UTC+5:30, Steven D'Aprano wrote: On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: On 9/5/2012 8:48 AM, Ramchandra Apte wrote: and a==True should be automatically changed into memory comparison. I have no idea what that means. I interpret this as meaning that a == True should be special-cased by the interpreter as a is True instead of calling a.__eq__. -- Steven Steven you are right. -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Thursday, 6 September 2012 01:54:45 UTC+5:30, Walter Hurry wrote: On Wed, 05 Sep 2012 15:03:16 -0400, Terry Reedy wrote: On 9/5/2012 8:45 AM, Ramchandra Apte wrote: snip These ever increasing extra blank lines with each quote are obnoxious. Consider using a news reader with news.gmane.org instead of google crap. Or snip heavily. +1. And the duplicated posts. Enough of him. Bozo bin it is. I really don't know why Google Groups is double-posting. -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Wednesday, 5 September 2012 19:43:30 UTC+5:30, Steven D'Aprano wrote: On Wed, 05 Sep 2012 05:48:26 -0700, Ramchandra Apte wrote: Seeing this thread, I think the is statment should be removed. It has a replacement syntax of id(x) == id(y) A terrible idea. Because is is a keyword, it is implemented as a fast object comparison directly in C (for CPython) or Java (for Jython). In the C implementation x is y is *extremely* fast because it is just a pointer comparison performed directly by the interpreter. Because id() is a function, it is much slower. And because it is not a keyword, Python needs to do a name look-up for it, then push the argument on the stack, call the function (which may not even be the built-in id() any more!) and then pop back to the caller. And worst, *it doesn't even do what you think it does*. In some Python implementations, IDs can be reused. That leads to code like this, from CPython 2.7: py id(spam ham[1:]) == id(foo bar[1:]) True You *cannot* replace is with id() except when the objects are guaranteed to both be alive at the same time, and even then you *shouldn't* replace is with id() because that is a pessimation (the opposite of an optimization -- something that makes code run slower, not faster). and a==True should be automatically changed into memory comparison. Absolutely not. That would be a backward-incompatible change that would break existing programs: py 1.0 == True True py from decimal import Decimal py Decimal(1.) == True True -- Steven the is statement could be made into a function -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On Wed, 05 Sep 2012 22:47:14 +, Oscar Benjamin wrote: In news.gmane.comp.python.general, you wrote: On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] You are making unjustified assumptions about the distribution of letters in the words. This might be a list of long chemical compounds where the words typically differ only in their suffix. It might be a list of people with titles: Actually, I'm not. I'm stating exactly what assumptions I'm making to get my calculation. I'm comparing *random* character strings or bitstrings. Excuse me, you are not. You are comparing English words which are highly non-random. Evidently we have different understandings of what 'random' means. I don't think it's unreasonable to say that strings drawn uniformly from the set of all strings in the English language (having a given number of characters) is random. The distribution is not uniform over the set of all possible character strings but it is still random. I think Johannes deliberately chose these strings to emulate a particular kind of 'real' distribution of strings that might occur in practise. Of course for some real applications, your strings being compared will be English words. And for other applications, they will be strings of numeric digits uniformly distributed between 2 and 3. Or taken from a Gaussian distribution centered around 7000. Or strings made up of deeply nested sets of parentheses (( ... )). Whichever special distribution of strings you pick, I don't think calling them random is terribly useful in context, even if they are generated randomly from some non-uniform distribution. But you know, it really doesn't make a difference. Equality testing will *still* be O(N) since the asymptomatic behaviour for sufficiently large string comparisons will be bounded by O(N). Multiplicative constants (half the string versus 0.001 of the string) do not matter. I may have been overly-conservative earlier when I said that on average string equality has to compare half the characters. I thought I had remembered that from a computer science textbook, but I can't find that reference now, so possibly I was thinking of something else. (String searching perhaps?). In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). But I'm not so sure about the average case. Further thought is required. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: HTMLParser skipping HTML? [newbie]
Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. No errors, but some of the tags seem to go missing for no apparent reason - any advice? I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( Code: import urllib2 from HTMLParser import HTMLParser from GetHttpFileContents import getHttpFileContents # create a subclass and override the handler methods class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print Start tag:\n\t, tag for attr in attrs: print \t\tattr:, attr # end for attr in attrs: # def handle_endtag(self, tag): print End tag :\n\t, tag # def handle_data(self, data): if data != '\n\n': if data != '\n': print Data :\t\t, data # end if 1 # end if 2 # # # - # def removeHtmlFromFileContents(): TextOut = '' parser = MyHTMLParser() parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) return TextOut # # - # if __name__ == '__main__': TextOut = removeHtmlFromFileContents() Part of the output: End tag : script Start tag: title Data :Bob Aalsma - Nederland | LinkedIn End tag : title Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') End tag : script Start tag: link attr: ('rel', 'stylesheet') attr: ('type', 'text/css') attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') End tag : script End tag : head But the source text for this is [and all of the meta ... seem to go missing: /script titleBob Aalsma | LinkedIn/title link rel=stylesheet type=text/css href=https://s3-s.licdn.com/scds/concat/common/css?h=7d22iuuoi1bmp3a2jb6jyv5z5; link rel=stylesheet type=text/css href=https://s4-s.licdn.com/scds/concat/common/css?h=b1io9ndljf1bvpack85gyxhv4-6qrj4gxbwq8loasfnyfmyuphe-dhog2e5h8scik4whkpqccnzou-dmo1gwj6nlhvdvzx7rmluambv-69sgyia02rmcjmco0t9d3xpvo; meta name=LinkedInBookmarkType content=profile meta name=ShortTitle content=Bob Aalsma meta name=Description content=Bob Aalsma: Project Manager at DripFeed in the Information Services industry (Amsterdam Area, Netherlands) meta name=UniqueID content=24198692 meta name=SaveURL content=/profile/view?id=24198692amp;authType=nameamp;authToken=KhOG /head No offense and thanks for the reminder. My background is software packages in 3GL, where different platforms mean different editors which mean it is sometimes difficult to recognize the end of blocks, especially when nested. No need for that here, no. I think it also means I'm still not really satisfied with my commenting in Python... -- http://mail.python.org/mailman/listinfo/python-list
Re: simple client data base
Mark R Rivet wrote: Hello all, I am learning to program in python. I have a need to make a program that can store, retrieve, add, and delete client data such as name, address, social, telephone number and similar information. This would be a small client database for my wife who has a home accounting business. Among programming languages Python is exceptionally easy to learn, and rocks for the kind of app you describe, but your goal is not realistic. Simple is better than complex, but what you can build at this point is far from what a professional accountant with her own business needs from a client database manager. I have been reading about lists, tuples, and dictionary data structures in python and I am confused as to which would be more appropriate for a simple database. Those are good classes to read about, and I dare say that most Pythoneers at some time faced confusion as to which were most appropriate for the problem at hand. You'd need of all them and more, a whole freak'in bunch more, to build a professional quality contact manager app. I know that python has real database capabilities but I'm not there yet and would like to proceed with as simple a structure as possible. Can anyone give me some idea's or tell me which structure would be best to use? Maybe its a combination of structures? I need some help. comp.lang.python tries to be friendly and helpful, and to that end responders have read and answered your question as directly as possible. There's good stuff available for Python. Mark, there is absolutely no chance, no how, no way, that your stated plan is a good idea. Fine CRM apps are available for free; excellent ones for a few dollars. You're reading about lists, tuples, and dictionary data? Great, but other home accounting businesses have their client databases automatically synced with their smart-phones and their time-charging and their invoicing. -Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: HTMLParser skipping HTML? [newbie]
Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. No errors, but some of the tags seem to go missing for no apparent reason - any advice? I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( Code: import urllib2 from HTMLParser import HTMLParser from GetHttpFileContents import getHttpFileContents # create a subclass and override the handler methods class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print Start tag:\n\t, tag for attr in attrs: print \t\tattr:, attr # end for attr in attrs: # def handle_endtag(self, tag): print End tag :\n\t, tag # def handle_data(self, data): if data != '\n\n': if data != '\n': print Data :\t\t, data # end if 1 # end if 2 # # # - # def removeHtmlFromFileContents(): TextOut = '' parser = MyHTMLParser() parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) return TextOut # # - # if __name__ == '__main__': TextOut = removeHtmlFromFileContents() Part of the output: End tag : script Start tag: title Data :Bob Aalsma - Nederland | LinkedIn End tag : title Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') End tag : script Start tag: link attr: ('rel', 'stylesheet') attr: ('type', 'text/css') attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') End tag : script End tag : head But the source text for this is [and all of the meta ... seem to go missing: /script titleBob Aalsma | LinkedIn/title link rel=stylesheet type=text/css href=https://s3-s.licdn.com/scds/concat/common/css?h=7d22iuuoi1bmp3a2jb6jyv5z5; link rel=stylesheet type=text/css href=https://s4-s.licdn.com/scds/concat/common/css?h=b1io9ndljf1bvpack85gyxhv4-6qrj4gxbwq8loasfnyfmyuphe-dhog2e5h8scik4whkpqccnzou-dmo1gwj6nlhvdvzx7rmluambv-69sgyia02rmcjmco0t9d3xpvo; meta name=LinkedInBookmarkType content=profile meta name=ShortTitle content=Bob Aalsma meta name=Description content=Bob Aalsma: Project Manager at DripFeed in the Information Services industry (Amsterdam Area, Netherlands) meta name=UniqueID content=24198692 meta name=SaveURL content=/profile/view?id=24198692amp;authType=nameamp;authToken=KhOG /head I can see that my Tester is not logging in: the reply from the site reads titleSign In | LinkedIn/title rather than titleBob Aalsma | LinkedIn/title. How can I tell which part is not correct? -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Thu, Sep 6, 2012 at 6:26 PM, Ramchandra Apte maniandra...@gmail.com wrote: the is statement could be made into a function It's not a statement, it's an operator; and functions have far more overhead than direct operators. There's little benefit in making 'is' into a function, and high cost; unlike 'print', whose cost is dominated by the cost of producing output to a console or similar device, 'is' would be dominated by the cost of name lookups and function call overhead. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
On 08/31/2012 11:05 PM, Antoine Pitrou wrote: Laszlo Nagy gandalf at shopzeus.com writes: How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. I would be very interested in a cross platform shared mem solution for python. Could you please point me to the right section. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
On 08/31/2012 11:05 PM, Antoine Pitrou wrote: Laszlo Nagy gandalf at shopzeus.com writes: How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. However perhap s I just misunderstood I never spent time to dive into the internals of multiprocessing. I would be very interested in a cross platform shared mem solution for python. Could you please point me to the right section. -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: But less exotically, Frank isn't entirely wrong. With current day computers, it is reasonable to say that any object has exactly one physical location at any time. In Jython, objects can move around; in CPython, they can't. But at any moment, any object has a specific location, and no other object can have that same location. Two objects cannot both be at the same memory address at the same time. It is however perfectly possible for one object to be at two or more memory addresses at the same time. In fact some work being done in PyPy right now is doing exactly that as part of Armin Rigo's software transactional memory implementation: when a global object is mutated a new copy is made and some threads may see the new version while other threads continue to see the old version until their transactions are comitted (or aborted). This means that global objects can be safely read from multiple threads without any semaphore locking. See http://mail.python.org/pipermail/pypy-dev/2012-September/010513.html -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Thu, Sep 6, 2012 at 7:34 PM, Duncan Booth duncan.booth@invalid.invalid wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: But at any moment, any object has a specific location, and no other object can have that same location. Two objects cannot both be at the same memory address at the same time. It is however perfectly possible for one object to be at two or more memory addresses at the same time. And of course, memory addresses have to be taken as per-process, since it's entirely possible for two processes to reuse addresses. But I think all these considerations of object identity are made with the assumption that we're working within a single Python process. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
On 08/31/2012 11:05 PM, Antoine Pitrou wrote: Laszlo Nagy gandalf at shopzeus.com writes: How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. I would be very interested in a cross platform shared mem solution for Python. The intention would be to excahnge mutexes and ctypes kind of data structures Could you please point me to the right section. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) It uses mmap() under windows. (I'm not an expert, but this is what I was said by others.) I did not know that multiprocessing can be used over TCP/IP. :) Probably I'll use zmq instead, because it has other nice features (auto reconnect, publisher/subscriber, multicast etc.) I would be very interested in a cross platform shared mem solution for python. Could you please point me to the right section. As far as I know, POSIX compatible shared memory does not exist on Windows. I remember a thread about this on the PostgreSQL mailing list - the Windows version of PostgreSQL somehow emulates shared memory too. I wanted to use shared memory because response times are much faster than TCP/IP. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
Hi Laszlo, There aren't a lot of ways to create a Python object in an mmap buffer. mmap is conducive to arrays of arrays. For variable-length structures like strings and lists, you need dynamic allocation. The C functions malloc and free allocate memory space, and file creation and deletion routines operate on disk space. However malloc doesn't allow you to allocate memory space within memory that's already allocated. Operating systems don't provide that capability, and doing it yourself amounts to creating your own file system. If you did, you still might not be able to use existing libraries like the STL or Python, because one address might refer to different locations in different processes. One solution is to keep a linked list of free blocks within your mmap buffer. It is prone to slow access times and segment fragmentation. Another solution is to create many small files with fixed-length names. The minimum file size on your system might become prohibitive depending on your constraints, since a 4-byte integer could occupy 4096 bytes on disk or more. Or you can serialize the arguments and return values of your functions, and make requests to a central process. I'm not sure about the technical details, but I was said that multiprocessing module uses mmap() under windows. And it is faster than TCP/IP. So I guess the same thing could be used from zmq, under Windows. (It is not a big concern, I plan to operate server on Unix. Some clients might be running on Windows, but they will use TCP/IP.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 09/06/2012 04:33 AM, Steven D'Aprano wrote: snip I may have been overly-conservative earlier when I said that on average string equality has to compare half the characters. I thought I had remembered that from a computer science textbook, but I can't find that reference now, so possibly I was thinking of something else. (String searching perhaps?). In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). But I'm not so sure about the average case. Further thought is required. For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement. So if we pick some set of characters, say 10 (or 256, it doesn't really matter), the number of possible strings is 10**N. The likelihood of not finding a mismatch within k characters is (1/10)**k The likelihood of actually reaching the end of the random string is (1/10)**N. (which is the reciprocal of the number of strings, naturally) If we wanted an average number of comparisons, we'd have to calculate a series, where each term is a probability times a value for k. sum((k * 9*10**-k) for k in range(1, 10)) Those terms very rapidly approach 0, so it's safe to stop after a few. Looking at the first 9 items, I see a value of 1.111 This may not be quite right, but the value is certainly well under 2 for a population of 10 characters, chosen randomly. And notice that N doesn't really come into it. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
Probably the fastest I/RPC implementation for Python should be OmniOrbpy: http://omniorb.sourceforge.net/ It's cross-platform, language-independent and standard-(Corba-) compliant. I don't want to use IDL though. Clients will be written in Python, and it would be a waste of time to write IDL files. I have seen a stand alone cross platform IPC server before that could serve channels, and send/receive messages using these channels. But I don't remember its name and now I cannot find it. Can somebody please help? If it's just for messaging, Spread should be interesting: http://www.spread.org/ Also cross-platform language-independent. Looks promising. This is what I have found about it: http://stackoverflow.com/questions/35490/spread-vs-mpi-vs-zeromq So, it really depends on whether you are trying to build a parallel system or distributed system. They are related to each other, but the implied connotations/goals are different. Parallel programming deals with increasing computational power by using multiple computers simultaneously. Distributed programming deals with reliable (consistent, fault-tolerant and highly available) group of computers. I don't know the full theory behind distributed programming or parallel programming. ZMQ seems easier to use. -- http://mail.python.org/mailman/listinfo/python-list
Need help fixing this error please:NameError: global name is not defined
Hi all, I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: CODE/// def databasebatchcall(self,tid, bid): con=cx_Oracle.connect('user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute(SELECT * FROM name) results = cur.fetchall() // From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated // File /home/dcroke/mdcFDACStringCall.py, line 21, in fetchbatchdata results = cur.fetchall() NameError: global name 'cur' is not defined // Thanks all, Shaun -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel d...@davea.name wrote: For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement. So if we pick some set of characters, say 10 (or 256, it doesn't really matter), the number of possible strings is 10**N. The likelihood of not finding a mismatch within k characters is (1/10)**k The likelihood of actually reaching the end of the random string is (1/10)**N. (which is the reciprocal of the number of strings, naturally) If we wanted an average number of comparisons, we'd have to calculate a series, where each term is a probability times a value for k. sum((k * 9*10**-k) for k in range(1, 10)) Those terms very rapidly approach 0, so it's safe to stop after a few. Looking at the first 9 items, I see a value of 1.111 This may not be quite right, but the value is certainly well under 2 for a population of 10 characters, chosen randomly. And notice that N doesn't really come into it. It's exactly right. You can obtain this result analytically from Johannes' formula above. Just replace 256 with 10 to get that the expected number of comparisons is (10/9)*(1 - 10**(-N)) The last term shows the dependence on N and is tiny even for N=9. Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
On Thu, Sep 6, 2012 at 8:45 PM, shaun shaun.wisema...@gmail.com wrote: CODE/// def databasebatchcall(self,tid, bid): con=cx_Oracle.connect('user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute(SELECT * FROM name) results = cur.fetchall() // From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated // File /home/dcroke/mdcFDACStringCall.py, line 21, in fetchbatchdata results = cur.fetchall() NameError: global name 'cur' is not defined // Not quite, actually. The traceback names a different function. Look in your code for a 'fetchbatchdata' function; it looks like you need to pass the cursor from one function to the other. To further assist, we'd need to see more of the code; but for a guess, I would say that you either need to make cur a function argument, or else (since this is class) an instance member, which you'd reference as 'self.cur'. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
On 09/06/2012 06:45 AM, shaun wrote: Hi all, I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: CODE/// def databasebatchcall(self,tid, bid): con=cx_Oracle.connect('user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute(SELECT * FROM name) results = cur.fetchall() // From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated // File /home/dcroke/mdcFDACStringCall.py, line 21, in fetchbatchdata results = cur.fetchall() NameError: global name 'cur' is not defined // Thanks all, Shaun is that really the function in line 21, or is it just a similar line? Notice the error gives you filename line number. I have no way to check either of those, but you can and should. What really stands out is the function name the error occurs in: fetchbatchdata() You don't show us the source to that function. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
shaun wrote: I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: def databasebatchcall(self,tid, bid): con=cx_Oracle.connect( 'user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute(SELECT * FROM name) results = cur.fetchall() This is not your real code. The above would give you a SyntaxError in the line cur.execute(SELECT * FROM name) From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated File /home/dcroke/mdcFDACStringCall.py, line 21, in fetchbatchdata results = cur.fetchall() NameError: global name 'cur' is not defined The offending line may not be indented correctly: def databasebatchcall(...): ... cur = con.cursor() ... results = cur.fetchall() This may be obscured by mixing tabs and spaces. However, without the actual code this is nothing but a guess. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamically scheduling Cron Jobs for Python Scripts.
On 06/09/12 08:21, coldfire wrote: I have a web scrapper script which run every day at 0100 hrs using cron Job over a shell account. Now what I am looking for is to re run the same script. 1 The script goes online to scrape some data including a schedule time for my meeting. I want to re run the script at that schedule time to send me a email. How can I do that? Plz Help Have a look at python-crontab http://pypi.python.org/pypi?name=python-crontab:action=display -- Vincent V.V. Oqapy https://launchpad.net/oqapy . Qarte https://launchpad.net/qarte . PaQager https://launchpad.net/paqager -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On 06/09/2012 05:24, Kushal Kumaran wrote: On Wed, Sep 5, 2012 at 3:11 PM, Stephen Anto charvigro...@gmail.com wrote: On Wed, Sep 5, 2012 at 2:10 PM, Kushal Kumaran kushal.kumaran+pyt...@gmail.com wrote: On Wed, Sep 5, 2012 at 12:20 PM, charvigro...@gmail.com wrote: On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying to catch up again with Python. I am now appearing for Job Interviews these days and I am wondering if anybody of you appeared for a Python Interview. Can you please share the questions you were asked. That will be great help to me. Finally I have decided to put best interview question and answers. Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python As I see from a quick glance, several of your answers seem to be copied from the python faq at http://docs.python.org/faq/. The copyright notice for the python.org website seems to be at http://docs.python.org/copyright.html. Do you have the Python Software Foundation's permission to copy large chunks of the python.org website and claim it as your own content? Thank you for your information, I really sorry for this, if possible could you note which are the questions taken from faq, we will remove it as early as possible. Since your website's Terms of Use state that you own the content, it is your problem to make sure whatever's there is there legally. Here's one example, though, to get you started: See the entry Why can’t I use an assignment in an expression? at http://docs.python.org/faq/design.html, and compare with the content under the identical heading on page 3 of the CorePython section. The section below it comes from here: http://svn.effbot.org/public/stuff/sandbox/pyfaq/is-there-a-tool-to-help-find-bugs-or-perform-static-analysis.xml -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
Sorry guys here is the full code for the class: #!/usr/bin/python # Echo client program import cx_Oracle import socket import pprint from struct import * import sys from binascii import * import time import datetime class StringCall: results=[] def databasebatchcall(self,termid, batchid): con = cx_Oracle.connect('user/user...@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') cur = con.cursor() cur.execute(SELECT * from name) results = cur.fetchall() def fetchbatchdata(self,results): for row in results: mer = row[0].ljust(25, ' ') mercity = row[1].ljust(13, ' ') mertype = row[2] merloc = row[3] mercount = row[4] mersec = row[5] acq = row[6] btime = row[7].strftime('%d%m') bmerch = str(row[8]).rjust(12, '0') termcur = row[9] acqbank = str(row[10]).rjust(24, '0') termtype = row[11] termsoftver = row[12] merbatch = str(row[13]).rjust(3, '0') reccount = str(row[14]).rjust(9, '0') amounttotal = str(row[15]).rjust(16, '0') cashback = str(row[16]).rjust(16, '0') deposit = str(row[17]).rjust(16, '0') def createbatchstrings(self): BatchHeaderPacket = \x01000\x0251.520%s0%s06060001%s%s%s%s0003 \x03 % (btime, bmerch, termcur, acqbank, termtype, termsoftver); ParameterPacket = \x01001\x0251.530401%s%sIE%s%s%s0%s%s0%s\x03 % (mer, mercity, mertype, merloc, termid, mercount, mersec, acq); TrailerPacket = \x01003\x0251.550%s00%s%s%s%s%s000\x03 % (btime, merbatch, reccount, amounttotal, cashback, deposit); cur.close() def returnbatchheader(self): return BatchHeaderPacket def returnparameterpacket(self): return ParameterPacket def returntrailerpacket(self): return TrailerPacket -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
This is the code in the script im calling: batchObject=StringCall() batchObject.databasebatchcall(termid, batchid) batchObject.fetchbatchdata() batchObject.createbatchstrings() BatchHeaderPacket =batchObject.returnbatchheader() ParameterPacket =batchObject.returnparameterpacket() TrailerPacket =batchObject.returntrailerpacket() print BatchHeaderPacket print ParameterPacket print TrailerPacket -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
On Thu, Sep 6, 2012 at 9:37 PM, shaun shaun.wisema...@gmail.com wrote: class StringCall: results=[] def databasebatchcall(self,termid, batchid): con = cx_Oracle.connect('user/user...@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') cur = con.cursor() cur.execute(SELECT * from name) results = cur.fetchall() This actually never sets 'results', which is a class variable. You should probably be using 'self.results' here; Python does not include class/instance members in scope automatically. Try using 'self.' for everything that you need to be maintained as state, and see if that solves your problem. But this looks to me like a case where you may not really even need a class at all. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Setting up a class
Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with self but im not too sure?? Any help would be appreciated. Thanks, Shaun -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
On 06/09/2012 12:37, shaun wrote: Sorry guys here is the full code for the class: #!/usr/bin/python # Echo client program import cx_Oracle import socket import pprint from struct import * import sys from binascii import * Don't use from something import *. It'll import a whole load of names. Import only those names you wish to use. import time import datetime class StringCall: results=[] def databasebatchcall(self,termid, batchid): con = cx_Oracle.connect('user/user...@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') cur = con.cursor() cur.execute(SELECT * from name) That line has an unterminated string literal (missing quote). That means that this file won't compile. results = cur.fetchall() As you're binding to results in the method, Python will assume that that name is local to the method. The results will be discarded as soon as the method returns, which it does right after. def fetchbatchdata(self,results): for row in results: mer = row[0].ljust(25, ' ') mercity = row[1].ljust(13, ' ') mertype = row[2] merloc = row[3] mercount = row[4] mersec = row[5] acq = row[6] btime = row[7].strftime('%d%m') bmerch = str(row[8]).rjust(12, '0') termcur = row[9] acqbank = str(row[10]).rjust(24, '0') termtype = row[11] termsoftver = row[12] merbatch = str(row[13]).rjust(3, '0') reccount = str(row[14]).rjust(9, '0') amounttotal = str(row[15]).rjust(16, '0') cashback = str(row[16]).rjust(16, '0') deposit = str(row[17]).rjust(16, '0') All of the names mer, mercity, etc, will be local to this method. def createbatchstrings(self): BatchHeaderPacket = \x01000\x0251.520%s0%s06060001%s%s%s%s0003 \x03 % (btime, bmerch, termcur, acqbank, termtype, termsoftver); ParameterPacket = \x01001\x0251.530401%s%sIE%s%s%s0%s%s0%s \x03 % (mer, mercity, mertype, merloc, termid, mercount, mersec, acq); TrailerPacket = \x01003\x0251.550%s00%s%s%s%s%s000\x03 % (btime, merbatch, reccount, amounttotal, cashback, deposit); cur.close() Where do the names btime, bmerch, etc, come from? They are certainly not the same as those in fetchbatchdata because this is a separate method. def returnbatchheader(self): return BatchHeaderPacket def returnparameterpacket(self): return ParameterPacket def returntrailerpacket(self): return TrailerPacket -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
Hi Chris, I'm changing it into multiple classes because the script is going to get much larger its more for maintainability reasons rather than functionality reasons. Thanks so much man it was the self fix you stated above. I woe you a pint of Guinness :D Thanks again, Shaun -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
In article 50485fca$0$29977$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). The best case is O(0), if either string is empty (ducking and running). -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting up a class
On Thu, Sep 6, 2012 at 8:00 AM, shaun shaun.wisema...@gmail.com wrote: Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with self but im not too sure?? Any help would be appreciated. Thanks, Shaun -- http://mail.python.org/mailman/listinfo/python-list You should take the smallest snippit of your code that shows your problem and copy it here along with traceback where it fails. Java is not python and vice versa, so some of your ideas will be confused for a while -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
In article 50484643$0$29977$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: On 9/5/2012 8:48 AM, Ramchandra Apte wrote: and a==True should be automatically changed into memory comparison. I have no idea what that means. I interpret this as meaning that a == True should be special-cased by the interpreter as a is True instead of calling a.__eq__. That would break classes which provide their own __eq__() method. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
n Thu, Sep 6, 2012 at 10:13 PM, Roy Smith r...@panix.com wrote: In article 50485fca$0$29977$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). The best case is O(0), if either string is empty (ducking and running). No, O(0) would be when the application decides not to compare at all. ChrisA (also ducking) -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting up a class
On 06/09/2012 13:00, shaun wrote: Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with self but im not too sure?? Any help would be appreciated. Thanks, Shaun You should have a look as a Python tutorial to help you get used to the language. It shouldn't take you long, provided that you remember that Python isn't Java and don't try to write Java in Python. :-) Here's one you could look at: Python for Java programmers http://python4java.necaiseweb.org/Main/TableOfContents -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help fixing this error please:NameError: global name is not defined
On Thu, Sep 6, 2012 at 10:07 PM, shaun shaun.wisema...@gmail.com wrote: Hi Chris, I'm changing it into multiple classes because the script is going to get much larger its more for maintainability reasons rather than functionality reasons. Doesn't necessarily have to be multiple classes. Python gives you the flexibility of dividing things in whatever way makes sense to your project. Maybe a class is right - I can't say without seeing all your code and knowing all your intentions - but if it's not, you don't have to feel constrained by it. This isn't Java where all code goes into a class! Thanks so much man it was the self fix you stated above. I woe you a pint of Guinness :D You're welcome! I'm a non-drinker, though, so you can drink it and think of me. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Language workbench written in python3
On Thursday, 6 September 2012 02:34:17 UTC+5:30, Nestor Arocha wrote: I'm developing a language workbench written in Python. The idea is to create an environment where grammars and translators can interact easily. https://github.com/nesaro/pydsl any comments, feedback or ideas? :) Translator means what precisely? -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Thursday, 6 September 2012 17:46:38 UTC+5:30, Roy Smith wrote: In article 50484643$0$29977$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: On 9/5/2012 8:48 AM, Ramchandra Apte wrote: and a==True should be automatically changed into memory comparison. I have no idea what that means. I interpret this as meaning that a == True should be special-cased by the interpreter as a is True instead of calling a.__eq__. That would break classes which provide their own __eq__() method. There is a way of doing this: make True.__req__ = lambda other: self is other -- http://mail.python.org/mailman/listinfo/python-list
Re: ===== Soft Skills Training In Chennai ======
On Thursday, 6 September 2012 11:26:21 UTC+5:30, mike pittenson wrote: Ayus Technologies offers Dot net training in chennai,java/j2ee training in chennai,SEO training in chennai,web designing training in chennai,soft skills training in chennai,Software Testing training in chennai. http://www.ayustechnologies.com/ More Information contact Mr, Jana 9080140107 this is spam - this is not related to python -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 05.09.2012 18:24, Steven D'Aprano wrote: On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] You are making unjustified assumptions about the distribution of letters in the words. This might be a list of long chemical compounds where the words typically differ only in their suffix. It might be a list of people with titles: Actually, I'm not. I'm stating exactly what assumptions I'm making to get my calculation. I'm comparing *random* character strings or bitstrings. Excuse me, you are not. You are comparing English words which are highly non-random. Not in my original post. If you read it again, you will clearly see that I was talking about purely random strings. And since you like to nitpick, I'll clarify further: I'm talking about bitstrings in which every bit of every character has the same probability of occurence, 50%. You then replied by mentioning probability distributions of characters in different languages/encodings, to which I tried giving a example as it might (and does) occur in the real world, like sorting a dictionary. But the original point is still valid: Sorting of randomized bitstrings is definitely not O(N), you got that wrong. You, on the other hand, are making vague assumptions which you do not care for formalize and yet you claim that the number of comparisons is equally likely to be 1, 2, 3, ..., N. The average then is. Without any explanation for this. At all. I will accept that my explanation was not good enough, but I strongly disagree that I gave no explanation at all. What possible explanation could there be that comparison of purely random bitstrings yields an equal amount of comparisons for its length? Herr Professor Frederick Schmidt Herr Professor Frederick Wagner ... Is your assumtion that we're comparing words that have the common prefix Herr Professor Frederick ? No, I am pointing out that *your* assumption that most string comparisons will halt close to the beginning of the string is an invalid assumption. Your assumption only holds for some non-random strings. Definitely not. It *especially* holds true for random strings. For random strings with an alphabet of size n, the probability that the first character needs to be compared is n^0, i.e. 1. The probability that the second character needs to be compared is n^(-1). For the xth character, it is n^(-x). This is due to the lazy abort in comparison and it results in the average number of comparisons being extremely short no matter the bitlength n, or O(log n). it's counting the number of character comparisons. Correct. But only out of an extremely limited subset of all possible string comparisons, namely those very few that happen when sorting lists of English words using a very specific algorithm, namely timsort. Yes, but this was to look at a real-world example (in which way more comparisons are needed than in the random case). You first were talking about randomized bitstrings (and so was I), then you brought up character sets and languages (which, for the original problem, are entirely irrelevant). Whatever figure you have calculated by taking this non-random selection, it is irrelevant to the question of the average performance of string equality given random strings. Correct. I gave the estimate for random strings in my very first post. For the sake of simple calculations, let's pretend that there are only 1000 five-letter strings possible. We want to know how many character- comparisons are done on average when testing two random five-letter strings for equality. To calculate this average, you must compare every string to every other string, *including* itself. This gives 1000*1000 = one million equality tests to be performed. For each equality test, we count the number of character comparisons performed, sum all those counts, and divide by 1e6. That is the average number of char comparisons for random strings of five letters. Easy enough. Since you didn't look at my original equation, here are some numbers and the program attached: 64 combinations for length 6 Char comparisons: 8064 Comparison cnt : 4096 Avg comparison : 1.97 128 combinations for length 7 Char comparisons: 32512 Comparison cnt : 16384 Avg comparison : 1.98 256 combinations for length 8 Char comparisons: 130560 Comparison cnt : 65536 Avg comparison : 1.99 512 combinations for length 9 Char comparisons: 523264 Comparison cnt : 262144 Avg comparison : 2.00 1024 combinations for length 10 Char comparisons: 2095104 Comparison cnt : 1048576 Avg comparison : 2.00 2048 combinations for length 11 Char comparisons: 8384512 Comparison cnt : 4194304 Avg comparison : 2.00 4096 combinations for length 12 Char comparisons: 33546240 Comparison cnt : 16777216 Avg comparison : 2.00 Hopefully now you'll see that your assumption O(n) is dead wrong. But that's not what you do. First you eliminate 900 out of the 1000 possible strings by only
Re: Setting up a class
On 09/06/2012 08:00 AM, shaun wrote: Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? Things don't get passed to a class. They get passed to an initializer (and to the constructor, but you've probably never used one of those), or to methods of the class. There's only one script in a given program, the other source files are modules. If code in one module wants to use code or data from another module, there are two general ways to do it. One is to use the from module1 import global1, func2 syntax. In this case, they effectively become globals of the current file. And the other is to use module1.func2() syntax, where you qualify where to find the function. As others have pointed out to you, from xxx import * is very risky, as you make everything global, and the reader can no longer tell where a particular symbol comes from. Further, any name collisions are silently dealt with, on the assumption that you REALLY know what you're doing. 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. You don't pass variables back to a script. If you mean return a value from a function, then say so. Note that a return statement takes a single object, but that object could very well be a tuple. So it's perfectly reasonable for a function to return as: return first, second And the caller might have done something like: a, b = myfunc() first will go into a,and second will go into b. This subtlety is because the expression first,second is a standard way to specify a tuple of size 2. And tuple unpacking can be done similarly with his, hers = expression. No restriction with size of 2, but you do want the same number of items in both places. There is no need to declare any variable, anywhere. If it needs an initial value, then assign it. Further, things 'at the top of the class' are class attributes, not just variables. How can you ask if there's anything you're not doing right when you post no code with your vague question? 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with self but im not too sure?? If one class method needs to call another method of the same class, you'll usually want to use the self object: class def method1(self): arg1 = 42 self.method2(arg1) def method2(self, value); ...dosomething interesting... Naturally, when it's a method of some other class, or when you need a different instance of the same class, then you'd better have an instance to use with it. someinstance.method2(arg1) -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Language workbench written in python3
On 09/06/2012 09:34 AM, Ramchandra Apte wrote: Translator means what precisely? Examples of translators include compilers, assemblers, and interpreters. They also include implementations like cfront, which translates from one high-level language to another lower-level language. (high and low being relative) -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting up a class
On 06/09/2012 8:20 AM, MRAB wrote: On 06/09/2012 13:00, shaun wrote: Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with self but im not too sure?? Any help would be appreciated. Thanks, Shaun You should have a look as a Python tutorial to help you get used to the language. It shouldn't take you long, provided that you remember that Python isn't Java and don't try to write Java in Python. :-) Here's one you could look at: Python for Java programmers http://python4java.necaiseweb.org/Main/TableOfContents The link given seems dated and incomplete - see operator overloading. Sorry I can't assist the OP. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 06.09.2012 10:33, Steven D'Aprano wrote: But you know, it really doesn't make a difference. Equality testing will *still* be O(N) since the asymptomatic behaviour for sufficiently large string comparisons will be bounded by O(N). Multiplicative constants (half the string versus 0.001 of the string) do not matter. Wrong, at least for randomized strings (i.e. every character with the same probability). O(N) is worst-case, O(log N) is correct for randomized strings. Then again, since you were nitpicking about Landau notation earlier this thread, every function bound by O(log N) is also bound by O(N), since, as you correctly stated, it's only a upper bound. We should be talking about the asymptotic sharp bound, i.e. capital Theta. I may have been overly-conservative earlier when I said that on average string equality has to compare half the characters. I thought I had remembered that from a computer science textbook, but I can't find that reference now, so possibly I was thinking of something else. (String searching perhaps?). In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). But I'm not so sure about the average case. Further thought is required. Yes, worst-case is O(N), best case O(1). Average is O(n log n). 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: Language workbench written in python3
On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: On 09/06/2012 09:34 AM, Ramchandra Apte wrote: Translator means what precisely? Examples of translators include compilers, assemblers, and interpreters. They also include implementations like cfront, which translates from one high-level language to another lower-level language. (high and low being relative) -- DaveA Is conversion from Python to C++ possible from this project? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to configure IDLE to use spaces instead of tabs for indenting?
Ramchandra Apte wrote: On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: I'm new to Python and have been using IDLE 3.2.3 to experiment with code as I learn. Despite being configured to use a 4 space indentation width, sometimes IDLE's smart indentation insists upon using width-8 tabs. From what I've been able to find on Google, this is due to a shortcoming in Tk. While it's not that big a deal in the grand scheme of things, I think it looks like poop, and I'd like to change IDLE to use 4-space indentation instead of tabs for all indentation levels. Is there any way for me to achieve what I want in IDLE, or do I have to start up my full-blown IDE if I want consistent 4-space indentation? Alex I think an IDE is better than IDLE. Try NINJA IDE. http://ninja-ide.org Agreed. I like PyDev in Eclipse, but sometimes I just want to try out something quick in the interpreter, to ensure I understand it or do a quick experiment. Since indentation is syntactically significant in Python, I think fixing the interpreter to produce good, readable, cut-and-pasteable, and Pythonic code is more important than a cosmetic feature, but less important than true bugs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to configure IDLE to use spaces instead of tabs for indenting?
On Thursday, 6 September 2012 19:13:23 UTC+5:30, Alex wrote: Ramchandra Apte wrote: On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: I'm new to Python and have been using IDLE 3.2.3 to experiment with code as I learn. Despite being configured to use a 4 space indentation width, sometimes IDLE's smart indentation insists upon using width-8 tabs. From what I've been able to find on Google, this is due to a shortcoming in Tk. While it's not that big a deal in the grand scheme of things, I think it looks like poop, and I'd like to change IDLE to use 4-space indentation instead of tabs for all indentation levels. Is there any way for me to achieve what I want in IDLE, or do I have to start up my full-blown IDE if I want consistent 4-space indentation? Alex I think an IDE is better than IDLE. Try NINJA IDE. http://ninja-ide.org Agreed. I like PyDev in Eclipse, but sometimes I just want to try out something quick in the interpreter, to ensure I understand it or do a quick experiment. Since indentation is syntactically significant in Python, I think fixing the interpreter to produce good, readable, cut-and-pasteable, and Pythonic code is more important than a cosmetic feature, but less important than true bugs. Agree. -- http://mail.python.org/mailman/listinfo/python-list
python docs search for 'print'
On 9/5/12 3:03 PM, Grant Edwards wrote: On 2012-09-05, Dave Angel d...@davea.name wrote: On 09/05/2012 01:47 PM, Grant Edwards wrote: Making the site's search box use Google or somesuch is probably the simplest solution. I'm not enough of a web guy to know how to do that, but I do know that some sites do handle site search that way. And google has some API's to make it relatively painless. And a license form to fill in and send, along with your check. I just saw the posting mentioning the pricing. So it is a simple simple solution, but it's probably not cheap enough... I followed the bug reporting instructions on the docs site and emailed d...@python.org and pointed them at this thread. I didn't catch if anyone else on this thread already did it. I guess we'll see what happens. -Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 09/06/2012 09:43 AM, Johannes Bauer wrote: snip Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. And I previously posted that for a character set of size 10, the average was 1. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Language workbench written in python3
On 09/06/2012 09:53 AM, Ramchandra Apte wrote: On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: On 09/06/2012 09:34 AM, Ramchandra Apte wrote: Translator means what precisely? Examples of translators include compilers, assemblers, and interpreters. They also include implementations like cfront, which translates from one high-level language to another lower-level language. (high and low being relative) Is conversion from Python to C++ possible from this project? I'll let the OP answer that. I don't know anything about it. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 06.09.2012 16:23, Dave Angel wrote: On 09/06/2012 09:43 AM, Johannes Bauer wrote: snip Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. O(log n) is what I meant, sorry! Damnit. And I previously posted that for a character set of size 10, the average was 1. For any given string n and and alphabet size l, the average is: sum(i = 0..n) (1 / (l ^ n)) So with larger word length, the total complexity constantly increases. The amount by which it increases however is shrinking exponentially with the word length. Therefore O(log n). Sorry about the n log n mistake, argh. Best regards thanks for the correction, 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: Comparing strings from the back?
On 06.09.2012 15:43, Johannes Bauer wrote: Wrong, at least for randomized strings (i.e. every character with the same probability). O(N) is worst-case, O(log N) is correct for randomized strings. ^^ Here I write the right thing. Then further below... Yes, worst-case is O(N), best case O(1). Average is O(n log n). ...I write the wrong thing. O(log n) is what I meant, as Dave correctly noticed. 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: Comparing strings from the back?
On 06.09.2012 16:23, Dave Angel wrote: On 09/06/2012 09:43 AM, Johannes Bauer wrote: snip Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. And I previously posted that for a character set of size 10, the average was 1. Again playing with the equations and thinking about it again. And I completely missed your point. It wasn't about n log n vs. log n. Both are wrong. This surprises me. I was somehow thinking about the limit of sum (1/n), n - infty. But since the summands are shrinking exponentially, the limit is different. I think the limit of the average comparisons for a given wordlength n against infinity with alphabet size l is l / (l - 1) i.e. for bitstrings it's 2 and for bytestrings it's 256/255. This would mean string comparison of randomized strings is O(1). Can that really be true? It looks like it. 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: Comparing strings from the back?
On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer dfnsonfsdu...@gmx.de wrote: Not in my original post. If you read it again, you will clearly see that I was talking about purely random strings. And since you like to nitpick, I'll clarify further: I'm talking about bitstrings in which every bit of every character has the same probability of occurence, 50%. That sort of string isn't a normal thing to be comparing, though. Here's an idea. Someone who's doing a lot of arguing in this thread should take Python, find the string comparison routine, and hack in some statistics-gathering. Then run *real code* on it. Maybe use this with one of those web frameworks and run your web site on it for an hour or two, or fire off some real scripts you really use. Then dump out the stats at the end. My guess: The bulk of string comparisons that get to actually comparing byte-for-byte will end up returning True. Most of the false comparisons will be proven earlier; if I understand correctly, Python will check for identity (easy true) and different lengths (easy false). But my guess could turn out to be flat wrong. In any case, it'll be far FAR more useful than arguing from totally random, or random word selection, or anything. Who's game? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Function for examine content of directory
Hi guys, I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) This is the code so far: -- import os path = v:\\workspace\\Python2_Homework03\\src\\ dirs = os.listdir( path ) filenames = {this.txt, that.txt, the_other.txt,this.doc,that.doc,this.pdf,first.txt,that.pdf} extensions = [] for filename in filenames: f = open(filename, w) f.write(Some text\n) f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) # This would print all the files and directories for file in dirs: print(file) for ext in extensions: print(Count for %s: %ext, extensions.count(ext)) -- When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: this.pdf the_other.txt this.doc that.txt this.txt that.pdf first.txt that.doc Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Count for .txt: 4 Count for .txt: 4 Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Any help is appreciated. T -- http://mail.python.org/mailman/listinfo/python-list
Re: Function for examine content of directory
On 06/09/12 15:56, Tigerstyle wrote: Hi guys, I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) This is the code so far: -- import os path = v:\\workspace\\Python2_Homework03\\src\\ dirs = os.listdir( path ) filenames = {this.txt, that.txt, the_other.txt,this.doc,that.doc,this.pdf,first.txt,that.pdf} extensions = [] Try using a set here instead of a list: extensions = set() for filename in filenames: f = open(filename, w) f.write(Some text\n) f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) and use: extensions.add(ext) This should take care of duplicates for you. Regards, Ian -- http://mail.python.org/mailman/listinfo/python-list
Accessing dll
I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Function for examine content of directory
On 06/09/2012 15:56, Tigerstyle wrote: Hi guys, I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) This is the code so far: -- import os path = v:\\workspace\\Python2_Homework03\\src\\ dirs = os.listdir( path ) filenames = {this.txt, that.txt, the_other.txt,this.doc,that.doc,this.pdf,first.txt,that.pdf} extensions = [] for filename in filenames: f = open(filename, w) f.write(Some text\n) f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) # This would print all the files and directories for file in dirs: print(file) for ext in extensions: print(Count for %s: %ext, extensions.count(ext)) -- When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: this.pdf the_other.txt this.doc that.txt this.txt that.pdf first.txt that.doc Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Count for .txt: 4 Count for .txt: 4 Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 That's because each extension can occur multiple times in the list. Try the Counter class: from collections import Counter for ext, count in Counter(extensions).items(): print(Count for %s: % ext, count) -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Sep 6, 2012 8:15 AM, Helpful person rrl...@yahoo.com wrote: I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? Richard -- Two things: 1) you would never use import name.dll, just like you don't use import math.py you would just import name. But that only works for Python libraries, which brings us to number 2 2) importing ctypes doesn't work any magic. Your c library is still a c library, not a python library. Ctypes provides functions to let you load a dll and makes calls to it, but you can't interact with the dll like python code. Doing that takes a lot more work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thu, Sep 6, 2012 at 11:07 AM, Helpful person rrl...@yahoo.com wrote: I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? You should start by reading the ctypes documentation, here: http://docs.python.org/library/ctypes.html . It has a lot of examples that ought to get you started. When you run into more specific problems, you're going to have to provide a lot more information before we can help you, including the specific documentation of the DLL you're trying to wrap, your platform, and python version. If you are not permitted to share those things, we may not be able to give you much help. Ctypes is very specific to the actual library you are accessing, and requires that you understand the requirements of the underlying DLL. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 06.09.2012 16:39, Chris Angelico wrote: In any case, it'll be far FAR more useful than arguing from totally random, or random word selection, or anything. Who's game? Okay, patched against Python 3.2.3: http://pastebin.com/PRRN53P6 To invoke display of the stats, compare the string pleasedumpstats as LHO, i.e.: pleasedumpstats Just ran it against a big script of mine which takes the stringified IMDb text files, parses it and dumps it into a sqlite3 database. Surprisingly little string comparisons however (the sqlite module without doubt uses its own routines internally). Although the database in the end has about 2 million records, these were the stats: strCmpEq 1017 strCmpLt 2802 strCmpGt 1633 strCmpTc 16219 strCmpCc 8570 which means 5452 comparisons of which 19% were equal and the rest inequal. Average string length is about 2.97 characters and aborted was in average after 1.57 characters. Maybe someone has a test which makes heavier use of string comparison. I don't want to make up something, however, since this is (by definition) going to be artificial. 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: Accessing dll
FYI My Python version is 2.5.4 -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Sep 6, 8:30 am, Jerry Hill malaclyp...@gmail.com wrote: You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html. It has a lot of examples that ought to get you started. When you run into more specific problems, you're going to have to provide a lot more information before we can help you, including the specific documentation of the DLL you're trying to wrap, your platform, and python version. If you are not permitted to share those things, we may not be able to give you much help. Ctypes is very specific to the actual library you are accessing, and requires that you understand the requirements of the underlying DLL. -- Jerry Thanks Jerry, I'll read the reference you posted. Unfortunately I know almost nothing about the dll and Python is loaded in some strange framework. I'll post back after a thorough read about Ctypes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 06.09.2012 17:36, Johannes Bauer wrote: pleasedumpstats And against a XML-reading C code generator that uses mako: strCmpEq 39670 strCmpLt 2766215 strCmpGt 2744002 strCmpTc 37430821 strCmpCc 14048656 Compared strings: 5549887 Equal: 0.7% Average wordlength: 6.74 chars Average comparelength: 2.53 chars 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: Comparing strings from the back?
On 09/06/2012 10:42 AM, Johannes Bauer wrote: On 06.09.2012 16:23, Dave Angel wrote: On 09/06/2012 09:43 AM, Johannes Bauer wrote: snip Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. And I previously posted that for a character set of size 10, the average was 1. Again playing with the equations and thinking about it again. And I completely missed your point. It wasn't about n log n vs. log n. Both are wrong. This surprises me. I was somehow thinking about the limit of sum (1/n), n - infty. But since the summands are shrinking exponentially, the limit is different. I think the limit of the average comparisons for a given wordlength n against infinity with alphabet size l is l / (l - 1) i.e. for bitstrings it's 2 and for bytestrings it's 256/255. This would mean string comparison of randomized strings is O(1). Can that really be true? It looks like it. (Just lost the internet in a storm, so I'm not sure how long it'll be before this sends.) Thanks, that was exactly my point. Since el is at least 2, the average number of comparisons is no larger than 2, for any value of N. That's why, when I'm visually comparing MD5 values, I usually only look at the first few, and last few hex digits. However, Chris Angelico (at 10:39) pointed out again that totally random strings aren't real-world equivalent. He has now proposed that somebody measure real-world cases here, by patching the string comparison to gather statistics. I think that's beyond me at this point. I only joined this thread when the cases under study were well-defined random, and therefore predictable. g -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
Am 06.09.2012 17:07, schrieb Helpful person: I am a complete novice to Python. Welcome! I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. Using ctypes, you can indeed load DLLs. Take a look at http://docs.python.org, which includes the documentation for the ctypes module but also general documentation and tutorials, which should be a starting point for you. I tried: import name.dll but this just gave me an error telling me that there was no such module. Like in VB or C, things are not that easy. You will always have to write some code that informs Python about the names and parameters of the functions in that DLL. Good luck! Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Sep 6, 8:28 am, Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote: Am 06.09.2012 17:07, schrieb Helpful person: I am a complete novice to Python. Welcome! I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. Using ctypes, you can indeed load DLLs. Take a look athttp://docs.python.org, which includes the documentation for the ctypes module but also general documentation and tutorials, which should be a starting point for you. I tried: import name.dll but this just gave me an error telling me that there was no such module. Like in VB or C, things are not that easy. You will always have to write some code that informs Python about the names and parameters of the functions in that DLL. Good luck! Uli Thanks. I've been working my way through that page, so far without any luck. I'm still trying. It seems strange that there is no documented way to simply access the dll, even incorrectly! If I could get Python to recognize the dll as a module I would at least have a place to start debugging. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Sep 6, 8:30 am, Jerry Hill malaclyp...@gmail.com wrote: You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html. It has a lot of examples that ought to get you started. The reference might help if I could get Python to recognize the dll as a module. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thu, Sep 6, 2012 at 12:46 PM, Helpful person rrl...@yahoo.com wrote: The reference might help if I could get Python to recognize the dll as a module. That's never going to happen. It's a DLL, not a python module. I think the documentation lays that out pretty explicitly. Have you experimented with the very first bit of example code in the documentation? What do you get if you do the following at the interactive interpreter? from ctypes import * print windll.insert your dll name here, without the .dll extension -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Sep 6, 9:58 am, Jerry Hill malaclyp...@gmail.com wrote: What do you get if you do the following at the interactive interpreter? from ctypes import * print windll.insert your dll name here, without the .dll extension -- Jerry I get: WinDLL 'my dll name without the dll extension , handle 41 at 2ace070 -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On 06/09/2012 17:58, Jerry Hill wrote: On Thu, Sep 6, 2012 at 12:46 PM, Helpful person rrl...@yahoo.com wrote: The reference might help if I could get Python to recognize the dll as a module. That's never going to happen. It's a DLL, not a python module. I think the documentation lays that out pretty explicitly. Have you experimented with the very first bit of example code in the documentation? What do you get if you do the following at the interactive interpreter? from ctypes import * print windll.insert your dll name here, without the .dll extension Or this: import ctypes dll_path = ... libc = ctypes.CDLL(dll_path) dir(libc) -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python class
On 9/6/2012 11:08 AM, Yves S. Garret wrote: I'd like to know if there are any online Python classes offered online from reliable institutions that you would recommend. Google 'online programming course python' for taught courses. At least 2 of MIT's self-guided OpenCourseWare courses use Python. http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/ http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/ If you wanted to do one of those, you might find a partner by asking here. There might be a matchmaking site, but I could not find one. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
How to print something only if it exists?
I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. I know I could simply use an if but ultimately there may be more elements of fld in the print and the print may well become more complex (most like will be formatted for example). Thus it would be good if there was some way to say print this if it exists. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to configure IDLE to use spaces instead of tabs for indenting?
On 9/6/2012 9:43 AM, Alex wrote: On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: I'm new to Python and have been using IDLE 3.2.3 to experiment with code as I learn. Despite being configured to use a 4 space indentation width, sometimes IDLE's smart indentation insists upon using width-8 tabs. [snip] Agreed. I like PyDev in Eclipse, but sometimes I just want to try out something quick in the interpreter, to ensure I understand it or do a quick experiment. You have two choices that come with the distribution: the console and IDLE. I prefer IDLE. IPython and other shells and IDEs are other choices. Since indentation is syntactically significant in Python, I think fixing the interpreter to produce good, readable, cut-and-pasteable, and Pythonic code is more important than a cosmetic feature, but less important than true bugs. IDLE is not the interpreter. As I said before, the IDLE editor *already* does what you want. The IDLE Shell is intended mainly for single-line inputs. For compound statements, it does automatic indenting, unlike the console (at least not on Windows). It uses a tab to guarantee that the code is visually indented. It does not use secondary prompts because a) they would not line up anyway with proportional fonts and b) they would appear in cut and paste copies. This probably count be improved, and has been discussed, but someone has to volunteer to write a patch that shows that it can be improved without introducing negative consequences. I would test one if one appears. For more than a three-line compound statement, I use the editor with a scratchpad file where editing is *much* easier. If the compound statement is a class or function definition, you need more statements anyway to actually exercise the definition. Hitting F5 to run is as easy as putting the cursor at the end of the statement and hitting Enter. And it runs multiple statements at once, not just one. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print something only if it exists?
On 9/6/2012 10:59 AM tinn...@isbd.co.uk said... I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. I know I could simply use an if but ultimately there may be more elements of fld in the print and the print may well become more complex (most like will be formatted for example). Thus it would be good if there was some way to say print this if it exists. You may be better off ensuring that fld is an appropriate length. One way may be tweaking the split to return the right numbers of elements: T = 1,2,3 flds = (T+,*5).split(,)[:5] flds ['1', '2', '3', '', ''] Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print something only if it exists?
On 09/06/2012 01:59 PM, tinn...@isbd.co.uk wrote: I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. I know I could simply use an if but ultimately there may be more elements of fld in the print and the print may well become more complex (most like will be formatted for example). Thus it would be good if there was some way to say print this if it exists. Would you like to define exists ? A list is not sparse, so all items exist if their subscript is less than the length of the list. So all you need to do is compare 2 to len(fld). But perhaps there's another approach. Just what DO you want to print if fld(1) exists, but fld(2) does not? Do you still want to print out day, fld(1), and balance? Or do you want to skip balance as well? if you literally want nothing printed for list elements beyond the end, then I'd add some extra empty-strings to the end of the list. fld.extend( * 5) Now, subscripts 0 through 4 inclusive will work, as specified. Alternatively, perhaps there's some association between the day and the fld(1), and the balance and the fld(2). in that case, probably you want to make a loop out of it, and only print each pair if they're both available. Something like: for tag, value in zip((something, day, balance), fld): print tag, value, -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 06/09/2012 15:01, David Hoese wrote: On 9/5/12 3:03 PM, Grant Edwards wrote: On 2012-09-05, Dave Angel d...@davea.name wrote: On 09/05/2012 01:47 PM, Grant Edwards wrote: Making the site's search box use Google or somesuch is probably the simplest solution. I'm not enough of a web guy to know how to do that, but I do know that some sites do handle site search that way. And google has some API's to make it relatively painless. And a license form to fill in and send, along with your check. I just saw the posting mentioning the pricing. So it is a simple simple solution, but it's probably not cheap enough... I followed the bug reporting instructions on the docs site and emailed d...@python.org and pointed them at this thread. I didn't catch if anyone else on this thread already did it. I guess we'll see what happens. -Dave Say thanks to Terry Reedy for http://bugs.python.org/issue15871 -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 9/6/2012 10:01 AM, David Hoese wrote: On 9/5/12 3:03 PM, Grant Edwards wrote: On 2012-09-05, Dave Angel d...@davea.name wrote: On 09/05/2012 01:47 PM, Grant Edwards wrote: Making the site's search box use Google or somesuch is probably the simplest solution. I'm not enough of a web guy to know how to do that, but I do know that some sites do handle site search that way. And google has some API's to make it relatively painless. And a license form to fill in and send, along with your check. I just saw the posting mentioning the pricing. So it is a simple simple solution, but it's probably not cheap enough... I followed the bug reporting instructions on the docs site and emailed d...@python.org and pointed them at this thread. I didn't catch if anyone else on this thread already did it. I guess we'll see what happens. I opened a tracker issue for a different solution. http://bugs.python.org/issue15871 -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Parsing ISO date/time strings - where did the parser go?
In Python 2.7: I want to parse standard ISO date/time strings such as 2012-09-09T18:00:00-07:00 into Python datetime objects. The datetime object offers an output method , datetimeobj.isoformat(), but not an input parser. There ought to be classmethod datetime.fromisoformat(s) but there isn't. I'd like to avoid adding a dependency on a third party module like dateutil. The Working with time section of the Python wiki is so ancient it predates datetime, and says so. There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. There are mentions of xml.utils.iso8601.parse in various places, but the xml module that comes with Python 2.7 doesn't have xml.utils. http://www.seehuhn.de/pages/pdate says: Unfortunately there is no easy way to parse full ISO 8601 dates using the Python standard library. It looks like this was taken out of xml at some point, but not moved into datetime. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print something only if it exists?
On 9/6/2012 1:59 PM, tinn...@isbd.co.uk wrote: I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. What fails is the indexing operation. You can prevent that by slicing rather than indexing: fld[1:2], fld[2:3]. These will give '' if there is no fld[1], fld[2]. Whether or not this is sensible depends on what you want the output to look like in these cases. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Language workbench written in python3
On Thursday, September 6, 2012 2:53:15 PM UTC+1, Ramchandra Apte wrote: On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: On 09/06/2012 09:34 AM, Ramchandra Apte wrote: Translator means what precisely? Examples of translators include compilers, assemblers, and interpreters. They also include implementations like cfront, which translates from one high-level language to another lower-level language. (high and low being relative) -- DaveA Is conversion from Python to C++ possible from this project? No, it is not currently possible for several reasons: * current parser implementation is a recursive descent parser. I haven't implemented an LR parser yet, although PLY lexers and parsers are supported. * Syntax Directed Translator is not fully implemented either. * Parser Trees are supported, but there is no clear method defined for converting them into ASTs (like antlr grammars) * Even with AST and SDT support, a Python to C++ translator will require more complex tools and a lot of coding. This tool is oriented to small DSLs parsing and translation; grammars like Python or C++ are too complex for the current implementation -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing ISO date/time strings - where did the parser go?
On 09/06/2012 09:27 PM, John Nagle wrote: In Python 2.7: I want to parse standard ISO date/time strings such as 2012-09-09T18:00:00-07:00 into Python datetime objects. The datetime object offers an output method , datetimeobj.isoformat(), but not an input parser. There ought to be classmethod datetime.fromisoformat(s) http://docs.python.org/library/datetime.html#datetime.datetime.strptime The ISO date/time format is dead simple and well-defined. strptime is quite suitable. but there isn't. I'd like to avoid adding a dependency on a third party module like dateutil. The Working with time section of the Python wiki is so ancient it predates datetime, and says so. There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. There are mentions of xml.utils.iso8601.parse in various places, but the xml module that comes with Python 2.7 doesn't have xml.utils. http://www.seehuhn.de/pages/pdate says: Unfortunately there is no easy way to parse full ISO 8601 dates using the Python standard library. It looks like this was taken out of xml at some point, but not moved into datetime. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print something only if it exists?
On 6 September 2012 18:59, tinn...@isbd.co.uk wrote: I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. What I might do is simply make a class that wraps the list. class SafeIndex: def __init__(self, lst, safety=): self.list = lst self.safety = def __getitem__(self, n): try: return self.list[n] except IndexError: return self.safety si = SafeIndex(range(20)) Then just index the SafeIndex with the print and abandon it after. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing ISO date/time strings - where did the parser go?
John Nagle na...@animats.com writes: There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. Hmm, I have some code that uses ISO date/time strings and just checked to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . I don't remember downloading that module (I must have done it and forgotten). I'm not sure what its outstanding issues are, as it works ok in the limited way I use it. I agree that this functionality ought to be in the stdlib. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing ISO date/time strings - where did the parser go?
On 09/06/2012 03:27 PM, John Nagle wrote: In Python 2.7: I want to parse standard ISO date/time strings such as 2012-09-09T18:00:00-07:00 into Python datetime objects. The datetime object offers an output method , datetimeobj.isoformat(), but not an input parser. There ought to be classmethod datetime.fromisoformat(s) but there isn't. I'd like to avoid adding a dependency on a third party module like dateutil. The Working with time section of the Python wiki is so ancient it predates datetime, and says so. There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. There are mentions of xml.utils.iso8601.parse in various places, but the xml module that comes with Python 2.7 doesn't have xml.utils. http://www.seehuhn.de/pages/pdate says: Unfortunately there is no easy way to parse full ISO 8601 dates using the Python standard library. It looks like this was taken out of xml at some point, but not moved into datetime. For working with datetime, see http://docs.python.org/library/datetime.html#datetime.datetime and look up datetime.strptime() Likewise for generalized output, check out datetime.strftime(). -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamically scheduling Cron Jobs for Python Scripts.
I want to re run the script at that schedule time to send me a email. Calculate how much time until the meeting. And spawn the script that will sleep that amount of time and then send email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote: I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? Richard I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows) pth = os.environ['path'].split(';') pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs')) os.environ['path'] = ';'.join(pth) -- http://mail.python.org/mailman/listinfo/python-list
Re: Function for examine content of directory
Thanks, just what I was looking for :-) T kl. 17:20:27 UTC+2 torsdag 6. september 2012 skrev MRAB følgende: On 06/09/2012 15:56, Tigerstyle wrote: Hi guys, I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) This is the code so far: -- import os path = v:\\workspace\\Python2_Homework03\\src\\ dirs = os.listdir( path ) filenames = {this.txt, that.txt, the_other.txt,this.doc,that.doc,this.pdf,first.txt,that.pdf} extensions = [] for filename in filenames: f = open(filename, w) f.write(Some text\n) f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) # This would print all the files and directories for file in dirs: print(file) for ext in extensions: print(Count for %s: %ext, extensions.count(ext)) -- When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: this.pdf the_other.txt this.doc that.txt this.txt that.pdf first.txt that.doc Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Count for .txt: 4 Count for .txt: 4 Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 That's because each extension can occur multiple times in the list. Try the Counter class: from collections import Counter for ext, count in Counter(extensions).items(): print(Count for %s: % ext, count) -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thursday, September 6, 2012 4:21:56 PM UTC-4, Tim Williams wrote: On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote: I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? Richard I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows) pth = os.environ['path'].split(';') pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs')) os.environ['path'] = ';'.join(pth) I should have also mentioned to look at LoadLibrary in the ctypes module. e.g. mylib=cdll.LoadLibrary('mylib.dll') -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing ISO date/time strings - where did the parser go?
On 9/6/2012 12:51 PM, Paul Rubin wrote: John Nagle na...@animats.com writes: There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. Hmm, I have some code that uses ISO date/time strings and just checked to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . I don't remember downloading that module (I must have done it and forgotten). I'm not sure what its outstanding issues are, as it works ok in the limited way I use it. I agree that this functionality ought to be in the stdlib. Yes, it should. There's no shortage of implementations. PyPi has four. Each has some defect. PyPi offers: iso8601 0.1.4 Simple module to parse ISO 8601 dates iso8601.py 0.1dev Parse utilities for iso8601 encoding. iso8601plus 0.1.6 Simple module to parse ISO 8601 dates zc.iso8601 0.2.0ISO 8601 utility functions Unlike CPAN, PyPi has no quality control. Looking at the first one, it's in Google Code. http://code.google.com/p/pyiso8601/source/browse/trunk/iso8601/iso8601.py The first bug is at line 67. For a timestamp with a Z at the end, the offset should always be zero, regardless of the default timezone. See http://en.wikipedia.org/wiki/ISO_8601;. The code uses the default time zone in that case, which is wrong. So don't call that code with your local time zone as the default; it will return bad times. Looking at the second one, it's on github: https://github.com/accellion/iso8601.py/blob/master/iso8601.py Giant regular expressions! The code to handle the offset is present, but it doesn't make the datetime object a timezone-aware object. It returns a naive object in UTC. The third one is at https://github.com/jimklo/pyiso8601plus This is a fork of the first one, because the first one is abandonware. The bug in the first one, mentioned above, isn't fixed. However, if a time zone is present, it does return an aware datetime object. The fourth one is the Zope version. This brings in the pytz module, which brings in the Olsen database of named time zones and their historical conversion data. None of that information is used, or necessary, to parse ISO dates and times. Somebody just wanted the pytz.fixedOffset() function, which does something datetime already does. (For all the people who keep saying use strptime, that doesn't handle time zone offsets at all.) John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
On 09/06/2012 04:33 PM, Dennis Lee Bieber wrote: snip Note that this difference mainly applies to how the processes are themselves are created... How the library wraps shared data is possibly different (I've never understood how a fork process can avoid memory conflicts if it has write access to common virtual memory blocks). Here's an approximate description of fork, at least for the memory aspects. During a fork, the virtual memory table is copied (that's descriptors for all mapped and allocated memory) but the memory itself is NOT. All the new descriptors are labeled COW (copy-on-write). As that process executes, the first time it writes in a particular memory block, the OS gets a memory fault, which it fixes by allocating a block of the same size, copying the memory block to the new one, and labeling it read/write. Subsequent accesses to the same block are normal, with no trace of the fork remaining. Now, there are lots of details that this blurs over, but it turns out that many times the new process doesn't change very much. For example, all the mappings to the executable and to shared libraries are theoretically readonly. In fact, they might have also been labeled COW even for the initial execution of the program. Another place that's blurry is just what the resolution of this table actually is. There are at least two levels of tables. The smallest increment on the Pentium family is 4k. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python class
On Fri, Sep 7, 2012 at 3:30 AM, Terry Reedy tjre...@udel.edu wrote: On 9/6/2012 11:08 AM, Yves S. Garret wrote: I'd like to know if there are any online Python classes offered online from reliable institutions that you would recommend. Google 'online programming course python' for taught courses. At least 2 of MIT's self-guided OpenCourseWare courses use Python. Note this subtle distinction. A Python course will (theoretically, at least!) teach you how to write Python code. A Python class is a collection of methods and stuff. A trivial and petty distinction, perhaps, but when you go searching the web, you'll get better results with the right word. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Function for examine content of directory
On Fri, Sep 7, 2012 at 12:56 AM, Tigerstyle laddosi...@gmail.com wrote: I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (.txt, .doc, etc.) If you haven't already, look into the Python 'dict' type; you may find it easier to work with for this sort of job. You can map an extension (txt) to its count (4) directly. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
HP Quality Center only works with ActiveState Python 2.5
Does anyone know why this is? I cannot find anything via Google about this, but HP says it is so. Of course it is now impossible to get ActiveState Python 2.5 for free. You can spend a $1000 for a copy. :) Anyway, it is irritating me that we are starting a new automation environment in Python, but we are being restricted to version 2.5 -- http://mail.python.org/mailman/listinfo/python-list