Class Variable Inheritance
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = [] def __init__(self): print 'called a' class b(a): def __init__(self): print 'called b' self.mapvar() def mapvar(self): self.mastervar.append(['b']) class c(b): def __init__(self): print 'called c' self.mapvar() def mapvar(self): super(c, self).mapvar() self.mastervar.append(['c']) if __name__ == '__main__': a1 = a() b1 = b() c1 = c() d1 = c() # Call C again print a1.mastervar print b1.mastervar print c1.mastervar print d1.mastervar What I don't understand is why mastervar gets modified by each _seperate instance_ of classes that happen to extend the base class 'a'. Shouldn't mastervar be contained within the scope of the inheriting classes? Why is it being treated like a global variable and being modified by the other instances? Thanks, Brian "bojo" Jones -- http://mail.python.org/mailman/listinfo/python-list
Re: Why PHP is so much more popular for web-development
Steve Holden wrote: > walterbyrd wrote: > >> "Once you start down the Dark path, forever will it dominate your >> desiny. Consume you, it will." >> - Yoda >> >> I'm fairly new to web-development, and I'm trying out different >> technologies. Some people wonder why PHP is so popular, when the >> language is flawed in so many ways. To me, it's obvious: it's because >> it's much easier to get started with PHP, and once somebody gets >> started with a particular language, that person is likely to stay with >> that language. >> >> Before you can even get started with Python web-development, you have >> to understand this entire alphabit soup of: CGI, FASTCGI, MOD_PYTHON, >> FLUP, WSGI, PASTE, etc. For me, configuring fastcgi has been the most >> difficult part of getting django to work. PHP developers don't have to >> bother with anything like that. With PHP, you just throw some code in >> the middle of your html file. >> I'm primarily a sysadmin, and I provide web hosting-like services to a community of developers who all want to do their own thing. An obvious, clean way to do this has, so far, eluded me. Of course I could shove a framework down the throats of my users, but if given the choice between picking up a language, or picking up a language, and an accompanying framework, which may or may not meet their needs, I think they'd pick the former. In fact, in 6 years, we've never had anyone say "boy I wish our web servers supported python". They've all been happily using PHP. I'm in a relatively small shop. But think about an ISP. If you need to support thousands of users who all have their own agendas, how exactly do you support that with Python? This is not a rhetorical question - I'd really like to know :) In short, I don't think it's the language, but deploying it in a web context that makes it less popular. If it were simpler, more ISPs might do it, more users would find what they need with Python instead of PHP, and it would become a more popular web language, IMHO. > The latter behavior is typical of programmers. The former is typical of > typical users. There are many people producing web sites who I wouldn't > let within yards of any of my code. but it's some kind of tribute to PHP > that it manages to satisfy so many of them. This doesn't mean that > grafting PHP features into Python mindlessly will improve the language. > I don't think anyone is saying the *language* itself needs improving. I think there needs to be a cleaner, simpler, more practical way to deploy Python as a generic web language instead of being forced to deploy it in the context of some other framework. No ISP wants to impose the implied limitations on their users, and the users would prefer not to have to learn a framework. Also, I just want to point out that in my discussions with other people who consider themselves primarily Python coders, there are plenty of them who still turn to PHP for web development. I got into Python for systems programming (sysadmin tasks and network programming). If I need to do web-based work, I'm likely to still use PHP because I have no idea how to deploy/maintain/support Python on the systems end of the equation. I'd love to be cured of that notion. brian. > The Python approach is a scalpel, which can easily cut your fingers off. > The PHP approach is a shovel, which will do for many everyday tasks. > > regards > Steve > -- Brian K. Jones Python Magazine http://www.pythonmagazine.com My Blog http://m0j0.wordpress.com jonesy at pythonmagazine dot com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Magazine: Issue 1 Free!
On 10/5/07, Paul McGuire <[EMAIL PROTECTED]> wrote: > > On Oct 5, 9:44 am, Grant Edwards <[EMAIL PROTECTED]> wrote: > > On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote: > > > > > I've just been told by the editors at Python Magazine that the first > > > issue is out. > > > > The first issue is issue number 10? > > > > That's a bit silly. > > > > -- > > Grant Edwards grante Yow! I can't decide > which > > at WRONG TURN to make > first!! > >visi.comI wonder if BOB > GUCCIONE > >has these problems! > > Probably Issue 10 as in "issued in October, being the 10th month", so > this is more of an id than it is a sequential index number. Just like > a social security number of 123-45-6789 does not mean you are the > 123,456,789th human born since the beginning of the SS system. > > But I grant that Issue number does have some connotation of sequence > to it, and if the next issue is something like 2 or 8, or really > anything other than 11, now THAT would be silly. And I'm sure that in > the future, when people are trying to amass the complete set of Python > Magazines, they'll wonder why those issues 1-9 of the first volume are > so hard to come by. > > But I suspect that, come January, we will see the release of Vol 2, > Issue 1. Just an artifact of having the first issue come out in some > month other than January. > > -- Paul > > -- > http://mail.python.org/mailman/listinfo/python-list > It's "Volume 1, Issue 10". A volume is a year. When January '08 is released, it will be "Volume 2, Issue 1". Keep the feedback coming! brian. -- Brian K. Jones Python Magazine http://www.pythonmagazine.com My Blog http://m0j0.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCon Feedback and Volunteers (Re: Pycon disappointment)
On Mar 16, 8:09 pm, [EMAIL PROTECTED] (Aahz) wrote: > If you did not like the programming this year (aside from the sponsor > talks) and you did not participate in organizing PyCon or in delivering > presentations, it is YOUR FAULT. PERIOD. EXCLAMATION POINT! I find this insulting, inexcusable, and utter nonsense. If putting the blame for a failed experiment on the backs of the good folks who paid good money for travel, lodging, and registration is also an experiment, you can hereby consider it also failed. The bottom line is that the people who are providing feedback in this forum are doing so *voluntarily*, and for the good of future PyCon events. They were sold a bill of goods, it was ill-comunicated, and they have taken their time to express that this is not a good idea moving forward. If it weren't for these people giving feedback, you would not have a complete experiment, because you would never have been able to prove or disprove your hypothesis. In fact, the people in this forum are just as important to the process as those who devised the experiment. As an experiment, it would seem that having an event organizer, who is presumably interested in the future success of the event, talking down to the people who would also like to see a better event in the future (and think they can make that happen - otherwise why bother giving feedback?), is doomed to failure. Of course, I'm only looking at how the experiment is being carried out. I claim ignorance as to the hypothesis. The rest of the points in your rant are all pretty commonly known by now, to most. At the end of the day, the buck has to stop somewhere, and that somewhere has to be with the organization that were charged with motivating a volunteer force, and the organization who set the expectations of the attendees. If you think that PyCon would've been better had there been more volunteers, then you should feed that back to the folks in charge of attracting and motivating said force. If you think it was simply a mis-labeling of the different classes of talks, feed that back to the folks who are in charge of such things. The point is that there are endless things that can be done which are more useful and productive than pointing fingers back at the people who support the conference by being attendees. They help build the conference too. A conference answers to its attendees, and that should be an expectation of anyone concerned with conference organization. Period. Exclamation point. Brian K. Jones Editor in Chief Python Magazine -- http://mail.python.org/mailman/listinfo/python-list
PyWorks Call for Papers extended
For those who don't follow PlanetPython, Python Magazine, OnLAMP, or some of the other Python news/blog outlets, PyWorks is a Python conference being held November 12-14, 2008, in Atlanta, by MTA (publisher of Python Magazine). The call for papers has been what I would call a success, but I've noticed that lots of people were at conferences when the deadline passed on July 25, and so I've been getting the bulk of the submissions over just the past few days! I'd like to see even more proposals, in the interest of offering the "best of the best" to our audience, so if you've held off because you missed the July 25 deadline, don't. If you would like to give a talk, or you'd like to see a talk given, please shoot me an email, preferably after perusing the Call for Papers page located here --> http://pyworks.mtacon.com/c/p/pyworks,cfp If you have any other questions about the conference, you can also send me an email, or join me (and the authors and editors of Python Magazine, among others) on irc in #pymag on irc.freenode.net Thanks to everyone here -- I've learned tons by lurking here over the past year or so. Hope to meet some of you in November! brian -- Brian K. Jones Python Magazine http://www.pythonmagazine.com My Blog http://www.protocolostomy.com -- http://mail.python.org/mailman/listinfo/python-list
Re: upload file using post to https server
I just did this yesterday with the 'poster' module after fumbling around with various other ideas, which in the end just produced a lot of code and didn't get me very far. Poster makes this pretty easy, and if you can't install it to the system python path, use 'setup.py install --user' and it'll put it in your home directory under ~/.local. With poster, it's a breeze. Here's what I've done. Hope it helps: #!/usr/bin/env python import random from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 import threading import time class Requestor(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.port = port def run(self): register_openers() post_param1 = 'cheddar' post_param2 = 'leicester' params, headers = multipart_encode({"pic": open("image.jpg"), "param1": post_param1, "param2": post_param2}) request = urllib2.Request("http://mybox:%s/"; % self.port, params, headers) curtime = time.time() response = urllib2.urlopen(request).read() perftime = time.time() - curtime print "Query time: %s\n" % perftime if __name__ == "__main__": for i in range(2000): port = random.choice(range(8885,8905)) t = Requestor(port) t.start() This is a basic threaded performance testing script that sends an image, and two other paramters, all in a POST request to a web server that opens multiple ports. If you don't need the threading, you should be able to rip the 'run()' method out of the class and just run it by itself (save an edit or two -- like hard-coding or otherwise replacing self.port). Good luck! brian On Fri, Sep 24, 2010 at 4:23 AM, Dennis Lee Bieber wrote: > On Thu, 23 Sep 2010 11:10:55 -0700 (PDT), cerr > declaimed the following in gmane.comp.python.general: > > > > values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' } > > > > try: > > data = urllib.urlencode( values ) > > > But the file doesn't seem to get there correctly. What I wanna do, is > > mocking the upload from the html site with my python script the > > html looks something like this: > > And are you expecting the server to somehow crawl down the socket > to > your machine to find the file, then suck it up? > >Where do you actually attach the file data to the outgoing response? > >Suggest you reference the RFC that added file upload to HTML: > http://www.faqs.org/rfcs/rfc1867.html > >In particular, section 3.3 > -=-=-=-=-=- > 3.3 use of multipart/form-data > > The definition of multipart/form-data is included in section 7. A > boundary is selected that does not occur in any of the data. (This > selection is sometimes done probabilisticly.) Each field of the form > is sent, in the order in which it occurs in the form, as a part of > the multipart stream. Each part identifies the INPUT name within the > original HTML form. Each part should be labelled with an appropriate > content-type if the media type is known (e.g., inferred from the file > extension or operating system typing information) or as > application/octet-stream. > -=-=-=-=-=- > >You've just supplied the file NAME part of the form, but not the > file data. > -- >Wulfraed Dennis Lee Bieber AF6VN >wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -- http://mail.python.org/mailman/listinfo/python-list
Re: creating python daemon ?
I don't believe you need to be doing all kinds of acrobatics with apache and your python process. On Linux and Unix machines, you can tell the stock syslog daemon that messages sent to a certain syslog facility are to be sent to a named pipe. So, if you tell syslog that, say, the local6 facility should go to a named pipe, then point apache at that to do its logging, then your script becomes as simple as reading from the named pipe. I did something years ago similar to this to get syslog messages sent to my jabber client. It's perl (it predates my conversion to python), but doing the same in python would be way easier :) The code is here: http://linuxlaboratory.org/snippets/2/ And an old article from Linux.com which explains the syslog bits is here: http://www.linux.com/archive/feature/36631 I occasionally still hear from people that all of it still works. hth. brian On Sun, Sep 26, 2010 at 5:20 AM, Stefan Schwarzer wrote: > Hi Daniel, > > On 2010-09-23 07:30, vineet daniel wrote: > > On Sep 22, 2:20 pm, de...@web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >>> On Sep 21, 9:47 pm, de...@web.de (Diez B. Roggisch) wrote: > vineet daniel writes: > > code that I am using is as follows : > >> > > #! /usr/bin/env python > > import sys,os > > pid = os.fork() > > os.chdir("/var/www/html/") > > os.setsid() > > os.umask(0) > > #this line will read apache log in real time as redirected from the > > CustomLog directive of Apache. > > log = sys.stdin.readlines() > > f = open('/var/www/logmongo.txt','a') # append log to this text file > > f.write(log) > > I guess you'll need some loop to process the input from > Apache. > > > There is a directive in Apache - CustomLog which can redirect logs to > > a script or another file by using Pipe. I googled about it and came to > > know that this works flawlessly with Perl as Apache treats Perl > > scripts as daemon, for Python to take input from Apache, it needs to > > work as daemon. Apache will then push its logs lines to this daemon as > > input. Perl takes this input as but python's stdin is not > > working as expected it just takes the file name as given in CustomLog > > directive using Pipe i.e if I use CustomLog '|/var//script.py' > > Are the _four_ ws intentional? > > > combined, what script reads is just the file name, how and why I am > > not able to figure it out. And thats the reason I am here. I hope > > you've got what I am trying to do. > > Do you have a line for the interpreter at the top of your > script, like > > #!/usr/bin/python > > Is the script executable (e. g. chmod +x script.py)? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -- http://mail.python.org/mailman/listinfo/python-list
Re: open file on mac
On Fri, Oct 8, 2010 at 10:41 AM, tinauser wrote: > hallo, i'm sorry if the question is very stupid, but i cannot > understand what i'm doing wrong here. > > i have this myModule.py > > class Starter: >def init(self,num): >print "hithere!" >print "the answer is ",num >import sys,os >print "path:",sys.path > print "bye" > >try: > ##f = open("/Users/lguerrasio/_myfold/initfile.py",'r') >f = open("initfile.py",'r') >f.close() >print "huurray!" >except IOError: >print "The file does not exist, exiting gracefully" >print "This line will always print" > > > the module is in the same folder of initfile > from terminal, i import sys and add to the path /Users/lguerrasio/ > _myfold/; > then i import the module and call > myModule.Starter().init(9) > > now,the file will be opened only if i give the full path, not if i > give only the name of the file, although the folder is in the path. > what am I missing? > sys.path, unless I've missed something, has nothing to do with *opening* a file. It has to do with importing a python module, so it should have no affect on your ability to simply open a file. On my mac, in the interpreter, running open() on a file in the same directory reported by os.path.abspath(os.path.curdir) succeeds without issue. What you might consider is doing something like open(os.path.join(os.path.dirname(__file__), 'initfile.py') That will insure that it always tries to open the file that's in the same directory as the module trying to open it, assuming that's what you want. If what you want is an import and not an open(), well... let us know :) brian > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCharm
I've been using PyCharm since the very first EAP releases, and downloaded 1.0 yesterday. I've tested out so many IDEs for use with Python, but PyCharm is the only one that gives me everything I want with just about zero work. Here's what won me over: 1. I can set up nose and coverage as a Run configuration, so I can run tests the way I want to with the click of the 'Run' button. 2. Best vim emulation of any IDE ever, and I'll note here that I used Komodo for some time. 3. The code inspections actually have saved me a good bit of work. In addition, they've helped me keep my code cleaner: it identifies unused variables, methods, and imports very well. It also has an autoimport feature, so if you reference a library you don't have imported yet, it'll suggest a lib to import, which you can accept with a keystroke. If more than one lib is a possibility, the UI for choosing which one to import is nicely done. 4. If I just want to create a file, I can. If I want to open a directory I can. It's not shoving its worldview down my throat by making me start whatever its notion of a "project" is. Yes, it puts a '.idea' directory in directories it opens, but I haven't seen that become an issue. 5. Git integration: the git integration piece might be the one piece that they got right early on: I never had any problems with it. 6. You can see a diff against local history, the current branch version, etc., pretty much no matter where you are in the interface. If you decide to push changes, and when the commit message dialog comes up you find yourself forgetting what you did, you can get a diff launched right from that window, and it's a decent diff interface. There are a few things I *don't* like about it, but they're pretty minor: 1. Only one default theme choice. It'd be nice to supply multiple themes and let me edit one instead of creating one from scratch. 2. docstrings: I find their docstring handling to be a little clunky. For one example, if you do this before declaring any classes in your module: """ this is a docstring """ It'll highlight that and tell you "this code appears to do nothing" 3. The Python interpreter is a little awkward. It's pretty obvious that there are two separate windows for input and output, and things are just being piped back and forth. There's a noticeable lag, and it's kind of annoying for someone who types fast and is used to the cli interpreter. As it stands, the cli interpreter is about the only thing I actually leave PyCharm for. 4. If you have a popup dialog open, the entire rest of the application is dead, so you can't scroll or switch files in your code pane when a dialog comes up. So when you want to know why that extra file is in your commit, you'll have to cancel out or run the diff tool. Overall, though, this is the best IDE for Python I've seen, and I'm sure it'll get even better with time. hth. brian On Thu, Oct 14, 2010 at 8:49 PM, alex23 wrote: > Jeffrey Gaynor wrote: > > Certainly give it a shot. The only other IDE I found that was > > remotely close to it was Komodo which costs a lot more > > (Jetbrains is offering a 50% off coupon as a promotional offer > > for a while.) > > I recently tried out PyCharm in anger after something (I forget what) > in Komodo was bothering me. In Komodo's defence, it supports Perl, > PHP, Python & Ruby, two of which I use daily, so replacing it would > require my buying two IDEs: PyCharm & PHPStorm. > > It would just be a damn sight easier if I didn't have to suffer under > PHP :( > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -- http://mail.python.org/mailman/listinfo/python-list