Re: Python as a HTTP Client
If you haven't discovered www.python.org yet I suggest going there :P. You will find there the documentation you need under the conspicuous name library reference. Specifically the modules you'd probably most be interested in are urllib/urllib2/httplib depending on what you need. Their may be other external modules which fit your task even better, try doing a search through the Python Package Index.. On 10 Nov 2005 05:02:32 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am writing a program that has to do some lightweight HTTP > communication with a webserver on the internet. I haven't checked, but > I'm sure I could do something lowlevel like opening a socket myself and > then send/receive everything myself on this (how do I do that?), but > I'd bet that Python have some module which is more high level. > Something that would just let me connect using an URL, send a few GETs, > and receive the answer as a string/file etc. > > Does this exist, and where can I read about it? > > /David > > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
On 23 Dec 2005 10:01:37 -0800, Joe <[EMAIL PROTECTED]> wrote: > It just seems that > Python developers think the whitespace thing is only an issue for > newbies. I think that many experienced users don't learn to like it, > but instead just learn to live with it. I disagree, I don't think you can be an experienced python programmer and not be comfortable with its syntax. On the other hand you *can* be an experienced programmer, but that's not the same thing. I don't care how much code you've written in Python, if your not comfortable with the syntax then you clearly don't use it with enough consistency to bring yourself to that point where you "own" it. There's nothing wrong with that, for whatever reason, maybe Python isn't for you.. but certainly don't blame it on something as small as significant indention, because we've all been there and its just not that hard to make the change. There are quite a few good high-level languages out there these days. This may be out of place, but I'd suggest checking out Ruby if you want something as powerful and "fun" to code in as Python but with more Perl-like syntax. It doesn't quite have as much of a diverse module selection as Python and Perl but that will change with time. Open source gives us an unprecendented amount of choices, try them all out.. I have, and I came up with Python because for me it is the "best fit." That may not be true in your case, which is perfectly fine. -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
On 23 Dec 2005 15:22:39 -0800, thakadu <[EMAIL PROTECTED]> wrote: > It is not really unique to Python as I have pointed out on this or > other forums before. The Occam (OCCAM?) language also uses significant > whitespace in much the same way as Python and there may also be others. > Your right of course, but I don't think it really even needs to be said. I mean whether or not Python is the only language that uses white space in a significant manner doesn't change the fact that.. well Python can do whatever the heck Python wants to do with its syntax. Honestly I wonder how so many coders actually came to be interested in the field -- one that pretty much thrives in part on its neverending ability to vary, grow, and change -- if something so small can warrant so much attention. -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
On 24 Dec 2005 18:36:32 -0800, Joe <[EMAIL PROTECTED]> wrote: > My original post was based on reading on Pythons developer list that it > was seriously considering some alternate grouping scheme, just because > "so many people keep asking". But, it seems that never happened. > > As for me, I'm not suggesting that braces are better than indentation. > In fact, requiring indentation is a good idea, and I agree that braces > can be quite ugly. It is the lack of visible block closing when there's > more than one level that I dislike. > > That would probably not be so bad if, like the recent post, you used an > editor that showed faint vertical lines. In fact, that's a very good > idea, since you really need a Python-aware editor anyhow. > You can always just document the end of the block with a comment, such as # end: if usr.password == password or something less elaborate :P. > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
On 26 Dec 2005 04:10:11 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > i think you can't call an editor python capable unless it > > shows you clearly hard (yuck)or soft tabs like View / > > Show Invisibles in textmate, View / view whitespace in > > komodo. > > Zeus for Windows has this View / View whitespace feature: > I personally don't care to see it, I'd rather it just did the soft -> hard conversion for me so I don't have to worry about it. Thats assuming hard tabs is defined as actual spaces rather then a tab character. If I'm getting those mixed up, switch 'em around or whatever. I find true tabs to be very annoying since different editors/programs seem to translate them differently, just give me spaces :P. Their are plenty of freeware and proprietary programs that do both and everything in between, don't feel like you have to be pushed into buying something. -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
On 12/25/05, Simon Hengel <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > I'm envisioning lots of convoluted one-liners which > > are more suitable to a different P-language... :-) > I feel that python is more beautiful and readable, even if you write > short programs. .. yes but there's a difference, some users of that "other" P-language seem to actually take some sort of ritualistic pride in their ability to condense code down to one convoluted line. The language is also a little more apt at it since it has a great deal of shorthand built in to the core language. Shorter is not necessarily better and I do support his opinion that reinforcing short as good isn't really what most programmers (who care about readability and quality) want to support. > > > How about """best compromize between shortness and readibility > > plus elegance of design"""? > I would love to choose those criteria for future events. But I'm not > aware of any algorithm that is capable of creating a ranking upon them. > Maybe we can come up with a solution. Any ideas? > I think code efficiency would be a better choice. A "longer" program is only worse if its wasting cycles on badly implemented algorithms. Code size is a really bad gauge, If your actually comparing size as in byte-to-byte comparison, you'll be getting a ton of implementations with absolutely no documentation and plenty of one letter variable names. I haven't checked the web site either, are you allowing third party modules to be used? If so, that causes even more problems in the comparison. How are you going to compare those who use a module vs implement it themselves in pure python? -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a refrence issue?
On 12/28/05, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > KraftDiner wrote: > > I understand that everything in python is a refrence > > > > I have a small problem.. > > > > I have a list and want to make a copy of it and add an element to the > > end of the new list, > > but keep the original intact > > > > so: > > tmp = myList > > > > tmp = myList is a shallow copy > > > > > tmp.append(something) > > print tmp, myList > > > > should be different... > > > Therefore it shouldn't be different. > > What you could do is make a second list > tmp = [] > > And then use the extend method: > > tmp.extend(myList) > tmp.append(someEntry) > > This would give you what you want, and there's more than one way to do this. > Such as from the python docs.. import copy x = copy.copy(y)# make a shallow copy of y x = copy.deepcopy(y)# make a deep copy of y > -carl > > -- > > Carl J. Van Arsdall > [EMAIL PROTECTED] > Build and Release > MontaVista Software > > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Quite honestly I've never heard of java being faster than.. well.. anything. Faster than Python? I really doubt it. Their are several libraries for game programming specifically as well as opengl, sdl, as well as several different audio systems/daemons.. I'd suggest browsing through the categories in python.org's module search engine. Disclaimer (:P): The majority of generalizations have some amount of exceptions, the java crack above was just my opinion - it was not really intended to offend any java addicts out there (the poor, miss-guided souls). On 11/29/05, Krystian <[EMAIL PROTECTED]> wrote: > Hi > are there any future perspectives for Python to be as fast as java? i > would like to use Python as a language for writing games. > > best regards > krystian > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: hard memory limits
James Stroud wrote: >Sorry Maurice, apparently in bash its "ulimit" (no n). I don't use bash, so I >don't know all of the differences offhand. Try that. > > The only shells I know of that uses unlimit is csh & tcsh.. bleh.. :) FWIW, I've had the same problem in openbsd, while ulimit will fix your problem temporarily you'll probably want to edit your default user class /etc/login.conf. In response to someone earlier, I think it's Linux here that is un-unix like, I do not think that characteristally a (non-admin) user is allowed unlimited access to ram in most varieties of unix, among other things and for good reason. -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Previously, on Jun 6, Thomas Bartkus said: # "bruno modulix" <[EMAIL PROTECTED]> wrote in message # news:[EMAIL PROTECTED] # > You mean the "wimp gui builder + db -> ui pipeline" model ? If yes, C # > doesn't have it, C++ doesn't have it (in fact most languages doesn't # > have it) - and # # > the fact is that C and C++ are usually considered as much # > more "serious and professionnal" than VB and the likes. # # Yes but there is another fact that must be considered. # Systems like VB (and the likes) are much more *productive* . # # The secret of that particular success has nothing to do with the language # and everything to do with the integrated GUI / IDE available to that # particular (VB) language. That's pretty arguable. C/C++ has no shortage of integrated GUI/IDE available especially if your willing to fork out the same kind of books that you would need to for VB. # # Anything that reduces the overhead involved in producing a # consistent/attractive/idiot proof user interface makes a far more # productive environment. # # Thomas Bartkus My 2 cents, I'm much more productive with Python and QT Builder as I am with VB and those aren't nearly as intergrated as VB's GUI/IDE. A language's productivity, I believe, rests on how high or low-level the language and its libraries are. Not just that though, productivity is also very much affected by the breadth of the libraries available. Sure, GUI RAD solutions increase development in a very real way, but you can find an offering for just about every language out there these days. # # -- # http://mail.python.org/mailman/listinfo/python-list # --- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Previously, on Jun 6, Thomas Bartkus said: # "James Tanis" <[EMAIL PROTECTED]> wrote in message # news:[EMAIL PROTECTED] # > Previously, on Jun 6, Thomas Bartkus said: # > # > # "bruno modulix" <[EMAIL PROTECTED]> wrote in message # > # news:[EMAIL PROTECTED] # > # > You mean the "wimp gui builder + db -> ui pipeline" model ? If yes, C # > # > doesn't have it, C++ doesn't have it (in fact most languages doesn't # > # > have it) - and # > # # > # > the fact is that C and C++ are usually considered as much # > # > more "serious and professionnal" than VB and the likes. # > # # > # Yes but there is another fact that must be considered. # > # Systems like VB (and the likes) are much more *productive* . # > # # > # The secret of that particular success has nothing to do with the # language # > # and everything to do with the integrated GUI / IDE available to that # > # particular (VB) language. # > # > That's pretty arguable. C/C++ has no shortage of integrated GUI/IDE # > available especially if your willing to fork out the same kind of books # > that you would need to for VB. # > # > # # > # Anything that reduces the overhead involved in producing a # > # consistent/attractive/idiot proof user interface makes a far more # > # productive environment. # > # # > # Thomas Bartkus # > # > My 2 cents, I'm much more productive with Python and QT Builder as I # > am with VB and those aren't nearly as intergrated as VB's GUI/IDE. A # > language's productivity, I believe, rests on how high or low-level the # > language and its libraries are. Not just that though, productivity is # > also very much affected by the breadth of the libraries available. # # When scripting, Windows or Linux, I also am much more productive with # Python. # When automating a process for another human being, I am much more productive # with a RAD tool like VB. The effort involved in creating the user front end # simply overwhelms all the considerable efficiencies of Python. # # When I code wxPython, I find I want to use VB to create/model my user # interface. Once I prototype my Windows (Frames!) using VB, I can then xlate # this to wxPython code. What I couldn't do without the VB IDE was visualize # and experiment with the impact of various layouts *before* I lay down code. # It is simply too onerous to experiment by code manipulation and too easy to # swish around visually with a mouse. # # When I use a GUI designer like wxGlade, I still find it awkward enough to # merit prototyping with the VB IDE and then mimic the windows I create with # wxGlade. # # > Sure, GUI RAD solutions increase development in a very real way, but you # > can find an offering for just about every language out there these days. # # Yes. But the tools available for Python are still primitive compared to RAD # tools like Delphi/Visual Studio. I still don't know enough wxPython to # understand what the barriers are to creating a RAD visual design and # construction tool similar to the Visual Studio environment. # My ravings here are simply the result of a suspicion - # # - The suspicion is that the only barrier is the Python (and Linux!) # communities grossly underestimating the value of such an undertaking. # Thomas Bartkus # Hmm, it's not that simple though. Unfortunately efforts get spread among the various projects, wxPython is only one among many. You seem set on wxPython, and its true, RAD projects based around that toolkit still seem to be in alpha/beta stages, but that does not go for all the toolkits. There are no barriers that I know of, but your comparing an application (vb) that has been 11+ years with one (wxglade) that has been around what.. maybe three years? # # # -- # http://mail.python.org/mailman/listinfo/python-list # --- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Show current ip on Linux
Previously, on Jun 13, Qiangning Hong said: # David Van Mosselbeen wrote: # > Hi, # > Im a newbie in Python, and also in Fedora Core 3. (Yes, Linux is fine # > man :-) # > # > My question is : How can i rwite a script that show my current ip. If i have # > more than one network card, the script must then show all used ip. # > # > It's important that this will work on a linux. i Have rwite some piece of # > code that realy work under Windows XP, but the same script wil not work on # > Linux. # > # > Verry thanks to all vulunteers. # > # # How about use the shell command "ifconfig | grep inet" ? # I think you mean ifconfig -a|grep 'inet ' He needs to see all the interfaces, no options will only print a help message. 'inet ' will get get rid of the inet6 addresses assuming he doesn't need those. # # -- # Qiangning Hong # # _ # ( so when I do a chroot /path /bin/bash, i can ) # ( see the processes ) # ( ) # ( outside of the chroot and i can kill those processes ) # ( * klieber claps for zhen oh go die ) # - #o \___ # v__v o \ O ) # (OO) ||w | # (__) || || \/\ # # -- # http://mail.python.org/mailman/listinfo/python-list # --- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: collect data using threads
Previously, on Jun 14, Jeremy Jones said: # Kent Johnson wrote: # # > Peter Hansen wrote: # > # > > Qiangning Hong wrote: # > > # > > # > > > A class Collector, it spawns several threads to read from serial port. # > > > Collector.get_data() will get all the data they have read since last # > > > call. Who can tell me whether my implementation correct? # > > > # > > [snip sample with a list] # > > # > > # > > > I am not very sure about the get_data() method. Will it cause data lose # > > > if there is a thread is appending data to self.data at the same time? # > > > # > > That will not work, and you will get data loss, as Jeremy points out. # > > # > > Normally Python lists are safe, but your key problem (in this code) is # > > that you are rebinding self.data to a new list! If another thread calls # > > on_received() just after the line "x = self.data" executes, then the new # > > data will never be seen. # > > # > # > Can you explain why not? self.data is still bound to the same list as x. At # > least if the execution sequence is x = self.data # >self.data.append(a_piece_of_data) # > self.data = [] # > # > ISTM it should work. # > # > I'm not arguing in favor of the original code, I'm just trying to understand # > your specific failure mode. # > # > Thanks, # > Kent # > # Here's the original code: # # class Collector(object): #def __init__(self): #self.data = [] #spawn_work_bees(callback=self.on_received) # #def on_received(self, a_piece_of_data): #"""This callback is executed in work bee threads!""" #self.data.append(a_piece_of_data) # #def get_data(self): #x = self.data #self.data = [] #return x # # The more I look at this, the more I'm not sure whether data loss will occur. # For me, that's good enough reason to rewrite this code. I'd rather be clear # and certain than clever anyday. # So, let's say you a thread T1 which starts in ``get_data()`` and makes it as # far as ``x = self.data``. Then another thread T2 comes along in # ``on_received()`` and gets as far as ``self.data.append(a_piece_of_data)``. # ``x`` in T1's get_data()`` (as you pointed out) is still pointing to the list # that T2 just appended to and T1 will return that list. But what happens if # you get multiple guys in ``get_data()`` and multiple guys in # ``on_received()``? I can't prove it, but it seems like you're going to have # an uncertain outcome. If you're just dealing with 2 threads, I can't see how # that would be unsafe. Maybe someone could come up with a use case that would # disprove that. But if you've got, say, 4 threads, 2 in each methodthat's # gonna get messy. # And, honestly, I'm trying *really* hard to come up with a scenario that would # lose data and I can't. Maybe someone like Peter or Aahz or some little 13 # year old in Topeka who's smarter than me can come up with something. But I do # know this - the more I think about this as to whether this is unsafe or not is # making my head hurt. If you have a piece of code that you have to spend that # much time on trying to figure out if it is threadsafe or not, why would you # leave it as is? Maybe the rest of you are more confident in your thinking and # programming skills than I am, but I would quickly slap a Queue in there. If # for nothing else than to rest from simulating in my head 1, 2, 3, 5, 10 # threads in the ``get_data()`` method while various threads are in the # ``on_received()`` method. Aaaagghhh.needmotrin.. # # # Jeremy Jones # I may be wrong here, but shouldn't you just use a stack, or in other words, use the list as a stack and just pop the data off the top. I believe there is a method pop() already supplied for you. Since you wouldn't require an self.data = [] this should allow you to safely remove the data you've already seen without accidentally removing data that may have been added in the mean time. --- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: collect data using threads
Previously, on Jun 14, Peter Hansen said: # James Tanis wrote: # > I may be wrong here, but shouldn't you just use a stack, or in other # > words, use the list as a stack and just pop the data off the top. I # > believe there is a method pop() already supplied for you. # # Just a note on terminology here. I believe the word "stack" generally # refers to a LIFO (last-in first-out) structure, not what the OP needs # which is a FIFO (first-in first-out). What can I say? Lack of sleep. # # Assuming you would refer to the .append() operation as "putting data on # the bottom", then to pop off the "top" you would use pop(0), not just # pop(). Right, except I'm not writing his code for him, and I don't think he expects me too. I was just referring to the existance of a pop() function, perhaps I should have said pop([int]) to be clearer. Its use would of course have to be tailored to his code depending on what he requires. # # Normally though, I think one would refer to these as the head and tail # (not top and bottom), and probably call the whole thing a queue, rather # than a stack. I agree, its been a while and I mixed the two names up, nothing more. --- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Server
[EMAIL PROTECTED] wrote: > Thanks, Fredrik - that definitely works. Now to get a little greedy - > is there something along those lines that is a bit more secure (i.e. > allows HTTPS, possibly with authentication)? Basically something that > you would feel more comfortable opening up to the Internet.. > > -- > http://mail.python.org/mailman/listinfo/python-list > You can do HTTPS with Twisted, you'll have to learn how to use Twisted which can sometimes be a task in itself. Most everything is pretty easy to learn although I get a little befuddled by the way they handle authentication myself. I personally think it's worth it though, Twisted is a great resource for rapid development of certain types of clients/servers. -- James Tanis Technical Coordinator Monsignor Donovan Catholic High School e: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Server
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > there's also apache, of course, and a bunch of others, including several > Python solutions (more or less pre-packaged). but the "open up" part > still sounds a bit risky. maybe you could turn things around, and let > the application "push" data to your server instead? Either way requires an open port, otherwise there's no way to negotiate new clients. If your in a closed environment that's not a concern, you could just define what clients to push to and when, but it sounds like he wants something a bit more dynamic. -- James Tanis Technical Coordinator Monsignor Donovan Catholic High School e: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Manipulate Large Binary Files
"Derek Tracy" <[EMAIL PROTECTED]> wrote: > > INPUT = open(infile, 'rb') > header = FH.read(169088) > > ary = array.array('H', INPUT.read()) > > INPUT.close() > > OUTF1 = open(outfile1, 'wb') > OUTF1.write(header) > > OUTF2 = open(outfile2, 'wb') > ary.tofile(OUTF2) > > > When I try to use the above on files over 2Gb I get: > OverflowError: requested number of bytes is more than a Python string > can hold > > Does anybody have an idea as to how I can get by this hurdle? > If it were me I'd loop until EOF and do small(er) read/write operations rather then attempt to put a whole 2gb file into a single string. Even if it was possible, you'd be using over 2gb of ram for a single operation. Also INPUT.read() returns a string from what I understand.. ary = array.array('c', INPUT.read()) might be more appropriate, but I'm not positive. Anyway I took a short look through array and using ary.fromfile(f, n) might be more appropriate. Using a loop, read some "machine values" with ary.fromfile(f, n) and write them with ary.tofile(f). Catch the EOFError when it is thrown.. I'd imagine that could work. -- <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} p.MsoPlainText, li.MsoPlainText, div.MsoPlainText {margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Courier New"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 --> James Tanis Technology Coordinator Monsignor Donovan Catholic High School e: [EMAIL PROTECTED] p: (706)433-0223 -- http://mail.python.org/mailman/listinfo/python-list