Re: Is behavior of += intentional for int?
Steven D'Aprano wrote: >On Sat, 29 Aug 2009 11:11:43 -0700, zaur wrote: > >> I thought that int as object will stay the same object after += but with >> another integer value. My intuition said me that int object which >> represent integer value should behave this way. > >If it did, then you would have this behaviour: > n = 3 # bind the name n to the object 3 saved_id = id(n) # get the id of the object n += 1# add one to the object 3 assert n == 4 # confirm that it has value four assert id(n) == saved_id # confirm that it is the same object m = 3 # bind the name m to the object 3 print m + 1 # but object 3 has been modified >5 > >This would be pretty disturbing behaviour, and anything but intuitive. Yes, indeed, and it's quite possible to write code like this in Fortran that produces exactly this result -- an integer constant gets modified. This used to get big yucks when we gathered around the keypunch, before we had the Obfuscated C Contest to amuse us. -- Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3: hex() on arbitrary classes
On Sep 1, 5:31 pm, Philipp Hagemeister wrote: > Mark Dickinson wrote: > > (...) If you want to be > > able to interpret instances of X as integers in the various Python > > contexts that expect integers (e.g., hex(), but also things like list > > indexing), you should implement the __index__ method: > > Thanks. Somehow forgot this magic method and deleted it by accident. I wonder whether it would make sense for the Python 2.x hex function to fall back to __index__ when __hex__ isn't defined. With the current setup, it's not clear how to write 2.x code that will also run (post 2to3 translation) properly on 3.x. -- Mark -- http://mail.python.org/mailman/listinfo/python-list
BeautifulSoup
Hi all,
if I have some HTML that looks like this:
http://BioCyc.org/ECOLI/NEW-IMAGE?
type=GENE-IN-CHROM-BROWSER&object=EG12309" onmouseover="return
overlib('Gene: yjtD
Product:
b> predicted rRNA methyltransferase, subunit of predicted rRNA
methyltransferase
Intergenic distances (bp):
b> yjjY< +400 yjtD +214 >thrL');">Gene: yjtDProduct: predicted rRNA methyltransferase, subunit of
predicted rRNA methyltransferaseIntergenic distances (bp): yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
is there an easy way to use BeautifulSoup to extract just the value of
the href attribute?
Thanks,
elsa
--
http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("""http://BioCyc.org/ECOLI/NEW-IMAGE?
... type=GENE-IN-CHROM-BROWSER&object=EG12309" onmouseover="return
... overlib('Gene: yjtDProduct: predicted rRNA methyltransferase, subunit of predicted rRNA
... methyltransferaseIntergenic distances (bp): yjjY< +400 yjtD +214 >thrL');">Gene: yjtDProduct: predicted rRNA methyltransferase, subunit of
... predicted rRNA methyltransferaseIntergenic distances (bp): yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
... """)
>>> soup.area["href"]
u'http://BioCyc.org/ECOLI/NEW-IMAGE
?\ntype=GENE-IN-CHROM-BROWSER&object=EG12309'
On Wed, Sep 2, 2009 at 1:25 AM, elsa wrote:
> Hi all,
>
> if I have some HTML that looks like this:
>
> http://BioCyc.org/ECOLI/NEW-IMAGE?
> type=GENE-IN-CHROM-BROWSER&object=EG12309" onmouseover="return
> overlib('Gene: yjtDProduct: b> predicted rRNA methyltransferase, subunit of predicted rRNA
> methyltransferaseIntergenic distances (bp): b> yjjY< +400 yjtD +214 >thrL');">Gene: yjtD >Product: predicted rRNA methyltransferase, subunit of
> predicted rRNA methyltransferaseIntergenic distances (bp): b> yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
>
>
> is there an easy way to use BeautifulSoup to extract just the value of
> the href attribute?
>
> Thanks,
>
> elsa
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Daemon process
On Wednesday 02 September 2009 05:57:02 Shan wrote: > I have XML RPC Server listening on a port. This XML RPC Server works > fine when i run it as foreground process. All the clients are able to > connect with the XML RPC Server. But when i run it as daemon(not using > &. I am doing it in python way only), then no clients are able to > connect with the Server. I didnt got any clue where i may be wrong. > Can any help me with this? I am using python 2.4 on Redhat 5.2 64 > X86_64 What does: "(not using &. I am doing it in python way only)" mean? How are you doing it? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On Wed, 02 Sep 2009 02:16:27 -0400, Terry Reedy wrote: > Steven D'Aprano wrote: > >>> I have read more that one person advocating leaving one's wi-fi base >>> open for anyone to use as the 'neighborly' thing to do. >> >> That's a different kettle of fish. You don't do anybody any harm by >> paying for Internet access for your neighbours (and anyone driving down >> the street with a laptop and wi-fi). > > Unless the 'neighbor' is your friendly local spam or malware merchant > ;-) Since they're sending spam through your account, it's the same as you sending the spam, and you're responsible for it. > The rationale I have seen is this: if one leaves the wi-fi router open > and illegal activity is conducted thru it, and there is no residual > evidence on the hard drives of on-premises machines, then one may claim > that it must have been someone else. On the other hand, if the router is > properly closed, then it will be hard to argue that someone hacked > trough it. > > There are, of course, flaws in this argument, and I take it as evidence > of intention to conduct illegal activity, whether properly so or not. So, if somebody leaves their car unlocked, is that evidence that they were intending to rob a bank and wanted a fast getaway car? If you leave your window open on a hot summer's night, is that evidence that you're planning to fake a burglary? If you leave your knife and fork unattended in a restaurant while you go to the toilet, is that evidence that you intended to stab the waiter and blame somebody else? I assume you would answer No to each of these. So why the harsher standard when it comes to computer crime? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: map
On Aug 31, 11:44 pm, Hendrik van Rooyen wrote: > On Monday 31 August 2009 11:31:34 Piet van Oostrum wrote: > > > But ultimately it is also very much a matter of taste, preference and > > habit. > > This is true, but there is another reason that I posted - I have noticed that > there seems to be a tendency amongst newcomers to the group to go to great > lengths to find something that will do exactly what they want, irrespective > of the inherent complexity or lack thereof of that which they are trying to > do. > > Now I cannot understand why this is - one could say that it is caused by an > eagerness to understand all the corners of the tool that is python, but > somehow it does not feel like that to me - I see it almost as a crisis of > confidence - as if the newbie lacks the self confidence to believe that he or > she is capable of doing anything independently. > > So whenever I can, I try to encourage people to just do it their way, and to > see what happens, and to hack using the interactive interpreter, to build > confidence by experimenting and making mistakes, and realizing that when you > have made a mistake, it is not the end of the world, - you can fix it and > move on. > > Don't know if this rant makes any sense... > > - Hendrik in my own defense - firstly, I was able to implement what I wanted to do with loops, and I used this to solve the problem I needed to. However, by asking *why* map didn't work, I now understand how map works, what contexts it may indeed be useful for, and what the alternatives are. To boot, you have all given me about 10 different ways of solving the problem, some of which use prettier (and probably faster) code than the loops I wrote... -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
On Wednesday 02 September 2009 08:52:55 Gabriel Genellina wrote: > En Tue, 01 Sep 2009 19:49:57 -0300, r escribió: > > On Sep 1, 1:52 pm, Hyuga wrote: > > (snip) > > > >> I'd say don't feel the troll, but too late for that I guess. > > > > The only trolls in this thread are you and the others who breaks into > > MY THREAD just for the knee-jerk reaction of troll calling! Even > > though you *did* offer some argument to one of the subjects of this > > thread, it was cancelled out by your trolling! > > Bueno, voy a escribir en el segundo lenguaje más hablado en el mundo > (español), después del mandarín (con más de 1000 millones de personas). El > inglés está recién en el tercer puesto, con menos de la mitad de hablantes > (500 millones). > > Si no me entendés, jodete. > > Fuente: http://www.wolframalpha.com/input/?i=languages+in+the+world What do you call someone who speaks three languages? - trilingual. What do you call someone who speaks two languages? - bilingual. What do you call someone who only speaks one language? - A stupid gringo! Nice one Gabriel - and with a link too! Looks like I am going to have to learn some Castilian, or something. :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
AttributeError: 'NoneType' object has no attribute 'get_text'
On Wed, Sep 2, 2009 at 10:11 AM, Raji Seetharaman wrote: > > Thanks MRAB. Now it works. > Raji.S -- http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
elsa wrote:
> if I have some HTML that looks like this:
>
> http://BioCyc.org/ECOLI/NEW-IMAGE?
> type=GENE-IN-CHROM-BROWSER&object=EG12309" onmouseover="return
> overlib('Gene: yjtD
Product:
> b> predicted rRNA methyltransferase, subunit of predicted rRNA
> methyltransferase
Intergenic distances (bp):
> b> yjjY< +400 yjtD +214 >thrL');">Gene: yjtD>Product: predicted rRNA methyltransferase, subunit of
> predicted rRNA methyltransferaseIntergenic distances (bp): b> yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
>
>
> is there an easy way to use BeautifulSoup to extract just the value of
> the href attribute?
>>> from BeautifulSoup import BeautifulSoup as BS
>>> html = ">> BS(html).find("area")["href"]
u'http://BioCyc.org/ECOLI/NEW-IMAGE?\ntype=GENE-IN-CHROM-
BROWSER&object=EG12309'
--
http://mail.python.org/mailman/listinfo/python-list
Re: Is behavior of += intentional for int?
> Carl Banks (CB) wrote: >CB> On Sep 1, 10:40 am, Piet van Oostrum wrote: >>> >>> Numbers are immutable by nature (math). The number 3.14 remains 3.14 >>> whatever you try to do with it. What you call an immutable number is in >>> fact a container that contains a number. >CB> I wouldn't agree with that terminology or logic. >CB> First of all "mutable number" is really just a short way to say >CB> "mutable number object". A number object in Python is not a number, >CB> it's just a representation of a number. Even if numbers are immutable >CB> by nature, an object representing a number need not be. Yes, that remark I made was more on the meta level. >CB> And if your number object is mutable, it does not make that object a >CB> container, at least not what I would call a container. A container >CB> you have to dereference somehow to get at the object inside, whereas a >CB> mutable number object you don't dereference: it acts like number as- >CB> is. If you read the OP, that was exactly what the OP (human) expected. That the list would contain some kind of reference to the number. And then of course you would have to dereference it to get the number. >CB> IOW, the first example below is a container, the second is not: >CB> num = [2] >CB> num[0] += 3 >CB> num = mutable_int(2) >CB> num += 3 >CB> (If you want to call the mutable number a container anyway, fine with >CB> me, I am not here to bicker.) A container is sufficient to get a >CB> layer of indirection if that's what you want the mutable number for. >CB> However, the mutable number has a performance advantage over using a >CB> container: it avoids the overhead of creating a new object. If you >CB> were using += in a loop like this, it could turn out to be significant >CB> savings. But since that's not common in Python I'd have to agree that >CB> this optimization opportunity is best done with a third-party C- >CB> extension, and not the standard library. That's an implementation detail. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with multiprocessing
[email protected] wrote: > I have a problem using multiprocessing in a simple way. I created a > file, testmp.py, with the following contents: > > --- > import multiprocessing as mp > > p = mp.Pool(5) > > def f(x): > return x * x > > print map(f, [1,2,3,4,5]) > print p.map(f, [1,2,3,4,5]) > > > > I'm using 2.6 r26:66713, so not quite bleeding edge. > > If I run 'python2.6 testmp.py' I get errors of exactly the kind > mentioned on docs.python.org for when multiprocessing is run using the > interactive interpreter. However, I'm obviously *not* running the > interactive interpreter. > > Any suggestions? I'm too lazy to read the docs, so I just tinkered: import multiprocessing as mp import testmp p = mp.Pool(5) def f(x): return x * x if __name__ == "__main__": print map(f, [1,2,3,4,5]) print p.map(testmp.f, [1,2,3,4,5]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with multiprocessing
On 09/02/2009 04:51 AM, Peter Otten wrote: [email protected] wrote: I have a problem using multiprocessing in a simple way. I created a file, testmp.py, with the following contents: --- import multiprocessing as mp p = mp.Pool(5) def f(x): return x * x print map(f, [1,2,3,4,5]) print p.map(f, [1,2,3,4,5]) I'm too lazy to read the docs, so I just tinkered: import multiprocessing as mp import testmp p = mp.Pool(5) def f(x): return x * x if __name__ == "__main__": print map(f, [1,2,3,4,5]) print p.map(testmp.f, [1,2,3,4,5]) Yes, to use the multiprocessing module, you must make your script importable, so runtime statements should go into a __main__ conditional. This way, when multiprocessing imports the module for each of its threads, the actual runtime code only gets executed once in the parent thread, which has the lock. At least, that is what I think is happening. import multiprocessing as mp def f(x): return x * x if __name__ == '__main__': p = mp.Pool(5) print map(f, [1,2,3,4,5]) print p.map(f, [1,2,3,4,5]) http://docs.python.org/library/multiprocessing.html -- http://invisibleroads.com Connecting Python developers with local businesses -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
Steven D'Aprano wrote: On Tue, 01 Sep 2009 20:48:19 +0200, David wrote: Il Tue, 1 Sep 2009 11:50:14 +0200, Andre Engels ha scritto: What about mailing lists? There exist well-functioning mailing lists with thousands of subscribers. Being a posting member of those will significantly increase your internet bill under your proposal. It's an implementation issue, it doesn't touch the sense of proposal. One possibility is register the mail list to official registers and mail from a subscriber to other subscribers will be excluded from taxation or will have a lower tax rate. An excessive mailing from a single or few subscribers can be easily detected, traced, filtered and, if the case, prosecuted. This can be done already, without the need for an email tax. ISPs could easily detect spammers, if they cared to. There are a few things that can already be done to cut the spam problem to manageable size: (1) Why aren't ISPs blocking port 25 for home users by default? My home ISP does, I can only send email through their mail server unless I ask them nicely, in which case I'd be responsible for any spam that leaves my home network. If I send spam, I'll be breaking my terms of service. (2) Why aren't ISPs cutting off detected spam bots? Owners of zombied PCs are menaces to society. ISPs are in the best position to detect PCs which are spamming, and alert the owner. If no action is taken in a week, warn the owner that they're in breach of their terms of service, and if the behaviour persists, cut the owner off until they clean up their PC. Repeat offenders should be banned. The preferred option these days is to slow down net access of the offenders, not cut them off completely. I'm not sure how many ISPs actually do that yet. -- http://mail.python.org/mailman/listinfo/python-list
[OT] evolution [was Re: An assessment of the Unicode standard]
This thread has intrigued me enough to bite the bullet and look up "r"'s posts. Oh my! They say a little learning is a dangerous thing, and this is a great example -- the only think bigger than r's ignorance and naivety on these topics is his confidence that he alone understands The Truth. Oh well, we were all kiddies like that once, so absolutely sure of ourselves on the basis of the most shallow paddling around on the shore of the sea of knowledge. I will limit myself to commenting on only one thing. (A good thing too, because this is long enough as it is.) On Tue, 01 Sep 2009 12:39:43 -0700, r wrote, quoting Steve (no relation : >> This might come as a bit of shock for you, but evolution awards those >> who are capable of adapting to complexity rather then those who expect >> things to be uniform. You, dear friend, and those who yearn for >> uniformity are the ones on the path to extinction. > > No evolution awards those that benefit evolution. You make it seem as > evolution is some loving mother hen, quite the contrary! Evolution is > selfish, greedy, and sometimes evil. And it will endure all of us... > > remember the old cliche "Nice guys finish last"? This is Not Even Wrong. Evolution isn't a *thing*, it is a *process*. Nothing exists to "benefit evolution", that's like saying that horses have long legs to "benefit running" or people have lungs to "benefit breathing". Horses have long legs so *they* can run, which is beneficial to *them* (but not earthworms, oak trees, eagles or sharks) because it enables them, indirectly, to survive long enough to produce offspring which are more likely to survive than they otherwise would be. Horses aren't the mechanism for running to make more running. Running is one of the ways horses survive long enough to make more horses. "R" is utterly confused if he thinks species live or die according to because they're benefiting evolution. Species live or die according to whether or not they reproduce, not due to services rendered to a process. Suggesting that species exist for the benefit of evolution is backwards -- it is like saying that we have computers and light bulbs and televisions and DVD players so that electricity can run through wires. Or that we build cars for the benefit of combustion. (This sort of nonsense, anthropomorphizing the process of evolution, seems to be unique to those on the right-wing of politics. Go figure.) Steve (the other Steve) is right -- species which are incapable of dealing with the complexity and dynamism of the world are doomed to extinction. Biologists have a word for stasis: "dead". The most vigorous, lively ecosystems are those that are complex, like rain forests (what used to be called "jungles" when I was a lad), coral reefs and mangroves. Messy, complicated, complex ecosystems are successful because they are resilient to damage -- a plague comes along and even if it kills off every individual of one species of fruit, there are a thousand different species unharmed. The sort of monoculture which "r" sings the praises of are fragile and brittle. Look at the Cavendish banana, nearly extinct because a disease is wiping the plants out, and there's not enough genetic variability in it to survive. (Fortunately there are dozens of varieties of bananas, so when the Cavendish becomes extinct, we'll still have bananas.) Or the Irish Potato Famine: millions of Irish dead from famine because 90% of their food intake came from a *single* source, potatoes, which in turn came from not just a single variety but just a handful of closely related individuals. (Well, also because the English were brutish thugs during the famine too, but that's just politics.) As for the idea "nice guys finish last", that's a ridiculous over- simplification. Vampire bats share their food with other vampire bats who otherwise would be hungry. Remoras stick to sharks, who carry them around for years without eating them. There's those little birds which climb into the mouths of crocodiles to clean their teeth while the crocodile sits patiently with it's mouth wide open. Wolves and wild dogs and hyenas hunt cooperatively. Baboons and chimpanzees form alliances. Penguins huddle together through the freezing months of darkness, and although the winds are so cold that the penguins on the outside would freeze to death, few of them do, because they all take their share of time in the centre. Monkeys cry out warnings when they see a leopard or a hawk, even though it puts them personally at risk. Meercats post sentries, who expose themselves to danger to protect the rest of the colony. And the most successful mammal on the planet, more successful than any other large animal, is also the most cooperative, least selfish species around. It is so unselfish, so cooperative, that individuals will rush into burning buildings to save complete strangers, and that cooperation has let the species colonize the entire
Re: An assessment of the Unicode standard
En Wed, 02 Sep 2009 04:58:43 -0300, Hendrik van Rooyen escribió: On Wednesday 02 September 2009 08:52:55 Gabriel Genellina wrote: Bueno, voy a escribir en el segundo lenguaje más hablado en el mundo (español), después del mandarín (con más de 1000 millones de personas). What do you call someone who speaks three languages? - trilingual. What do you call someone who speaks two languages? - bilingual. What do you call someone who only speaks one language? - A stupid gringo! LOL! Nice one Gabriel - and with a link too! Looks like I am going to have to learn some Castilian, or something. :-) Looks like we all will have to learn mandarin! A nice language but with a high entrance barrier for western people. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: using queue
Tim Arnold wrote: Hi, I've been using the threading module with each thread as a key in a dictionary. I've been reading about Queues though and it looks like that's what I should be using instead. Just checking here to see if I'm on the right path. The code I have currently compiles a bunch of chapters in a book (no more than 80 jobs at a time) and just waits for them all to finish: max_running = 80 threads = dict() current = 1 chaps = [x.config['name'] for x in self.document.chapter_objects] while current <= len(chaps): running = len([x for x in threads.keys() if threads[x].isAlive()]) if running == max_running: time.sleep(10) else: chap = chaps[current - 1] c = self.compiler(self.document.config['name'], chap) threads[chap] = threading.Thread(target=c.compile) threads[chap].start() current += 1 for thread in threads.keys(): threads[thread].join(3600.0) - but I think Queue could do a lot of the above work for me. Here is pseudocode for what I'm thinking: q = Queue(maxsize=80) for chap in [x.config['name'] for x in self.document.chapter_objects]: c = self.compiler(self.document.config['name'], chap) t = threading.Thread(target=c.compile) t.start() q.put(t) q.join() is that the right idea? I don't need that many threads; just create a few to do the work and let each do multiple chapters, something like this: class CompilerTask(object): def __init__(self, chapter_queue): self.chapter_queue = chapter_queue def __call__(self): while True: chapter = self.chapter_queue.get() if chapter is None: # A None indicates that there are no more chapters. break chapter.compile() # Put back the None so that the next thread will also see it. self.chapter_queue.put(None) MAX_RUNNING = 10 # Put the chapters into a queue, ending with a None. chapter_queue = Queue() for c in self.document.chapter_objects: chapter_queue.put(self.compiler(self.document.config['name'], c.config['name'])) chapter_queue.put(None) # Start the threads to do the work. for i in range(MAX_RUNNING): t = threading.Thread(target=CompilerTask(chapter_queue)) t.start() thread_list.append(t) # The threads will finish when they see the None in the queue. for t in thread_list: t.join() -- http://mail.python.org/mailman/listinfo/python-list
Problem w/ mysqldump
Hi:
I have the following python code:
import os
os.system("mysqldump -u root -pPASSWORD --opt spreadsheets > dump.sql")
This nicely creates the file...but the file is empty! The database exists
and has lots of data, I double-checked it. If there is nothing wrong with my
code, is there some way to do the same thing from within MySQL? Can I at
least print everything to screen and copy it? Where would I find my database
in Windoze?
TIA,
Victor
--
http://mail.python.org/mailman/listinfo/python-list
Re: [OT] evolution [was Re: An assessment of the Unicode standard]
Steven D'Aprano wrote: I'd like to add the following: It is an intriguing human trade to attribute emotions and reasons to things that have none. Intriguing because I haven't observed yet that it provides an advantage, but it happens so often that I can't exclude it either. I find that evolution makes more sense _to_me_ if I see it in the following perspective: If something can happen, it will happen, if there is a higher chance something can happen more often, then it will happen more often, though not necessaryly at the time the observer expects it -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
Am 01.09.2009 22:10, schrieb David: Il Mon, 31 Aug 2009 20:06:54 -0700 (PDT), r ha scritto: ... The system is definitely flawed. I am no internet expert so i don't really know what we could do to fix it. I do fear goverment or corporations taking over of the internet and robbing use of our freedom of speech under the pretense that they will *somehow* save us from the spammers. Something must be done however. I definitely agree with you on that point, that's why I'm making this proposal: the target is to reduce the spam *without* using armies of cybercops patrolling all over the net. Here is another idea: for spam senders pointing to servers under jurisdiction, size the server and check all incoming requests from users - if they try to do a deal, prosecute a few of them in the public for supporting a crime. (And of course if possible get hold of the spammers too). Sure there would be corner cases where for example a competitor might try to discredit a company, but in most cases, cui bono should be the spammer after all. T. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't set attribute?!
dolgion ch: >good to know about this __slots__ thing, i'll keep it in mind< What you have to keep in mind is that it's better to not use __slots__ unless you really need to. Generally you need it not for the purposes a person coming from a static language is tempted to use it for. It's mostly useful for small classes that don't need subclassing that have to be instantiated a large number of times. As far as I know, it's meant as a memory optimization, not a way to define things in a more explicit way. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
On Wed, Sep 02, 2009 at 06:43:12AM -0400, Victor Subervi wrote:
> Hi:
> I have the following python code:
> import os
> os.system("mysqldump -u root -pPASSWORD --opt spreadsheets > dump.sql")
> This nicely creates the file...but the file is empty! The database exists
> and has lots of data, I double-checked it. If there is nothing wrong with my
> code, is there some way to do the same thing from within MySQL? Can I at
> least print everything to screen and copy it? Where would I find my database
> in Windoze?
Are you sure the password you entered is correct? I tested the code and
it worked fine for me. However, when I used an incorrect password, it
returned an error and did create an empty file, just as you describe.
--
http://mail.python.org/mailman/listinfo/python-list
exec globals and locals
Hi,
Being fairly new to Python, I'm trying to figure out the best way to use the
exec statement and I must admit that I am a bit lost.
Consider this case:
exec "print 'a'" in {},{} [exp.1]
It means that I'm (kindly) asking the interpreter to execute the code
string "print 'a'" with empty globals and locals.
Considering that globals and locals are empty, I would expect [exp.1] to
raise an exception about 'print' not being known.
However, the evaluation of [exp.1] produces an output...
>>> exec "print 'a'" in {},{}
a
So, I decided to read more attentively the documentation and here is what
I've found:
"""
As a side effect, an implementation may insert additional keys into the
dictionaries given besides those corresponding to variable names set by the
executed code. For example, the current implementation may add a reference
to the dictionary of the built-in module __builtin__ under the key
__builtins__ (!).
"""
Putting aside the fact that implementation specifics are evil, I would like
to know if there is one way to force builtins not to be added to the scope?
I would rather add this by myself which, in my opinion, is a more explicit,
thus more pythonic, way of doing.
Any comment on this?
Regards,
Quentin
--
http://mail.python.org/mailman/listinfo/python-list
Re: Is it a bug?
Oops, missed out that... thanks On Sun, Aug 30, 2009 at 2:25 PM, Jan Kaliszewski wrote: > 30-08-2009 o 06:10:46 Abhishek Mishra wrote: > >> The single quote \' is the culprit. >> When you say words = ["Hi", "Whats up", "Bye"] and try print words, >> you get this - >> ['Hi', 'Whats up', 'Bye'] >> >> All double quotes converted to single ones. Now as for your input, >> notice the single quote in What's >> Now wrapping that word with single quotes won't be correct, so python >> uses double quotes to avoid any quote completion errors. >> But there's hardly much difference "foo" and 'foo' right? While in php >> you can notice some difference. >> >> Abhishek Mishra >> http://ideamonk.blogspot.com > > Hello, > > You posted your message only to me -- and probably wanted to post it > to the list? > > Cheers, > *j > > -- > Jan Kaliszewski (zuo) > -- http://mail.python.org/mailman/listinfo/python-list
Re: Is behavior of += intentional for int?
On Sep 2, 12:07 am, Tim Roberts wrote: > Steven D'Aprano wrote: > >On Sat, 29 Aug 2009 11:11:43 -0700, zaur wrote: > > >> I thought that int as object will stay the same object after += but with > >> another integer value. My intuition said me that int object which > >> represent integer value should behave this way. > > >If it did, then you would have this behaviour: > > n = 3 # bind the name n to the object 3 > saved_id = id(n) # get the id of the object > n += 1 # add one to the object 3 > assert n == 4 # confirm that it has value four > assert id(n) == saved_id # confirm that it is the same object > m = 3 # bind the name m to the object 3 > print m + 1 # but object 3 has been modified > >5 > > >This would be pretty disturbing behaviour, and anything but intuitive. > > Yes, indeed, and it's quite possible to write code like this in Fortran > that produces exactly this result -- an integer constant gets modified. > > This used to get big yucks when we gathered around the keypunch, before we > had the Obfuscated C Contest to amuse us. Many Fortran compilers these days pass scalars by value by default. Recently I had to compile a cicra-1972 Fortran program where I had to disable a lot of recent Fortran innovations (like from 1977) to get it to build properly. It turned out that it did try to modify a constant somewhere, but then it segfaulted because the compiler put that constant in read-only memory. (Whoever wrote the program originally was a smart cookie, BTW, it was super versatile for its time.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
Obviously I'm sure. It created the file. But the file was blank. How can I
do a mysqldump in mysql itself?
V
On Wed, Sep 2, 2009 at 8:13 AM, Nitebirdz wrote:
> On Wed, Sep 02, 2009 at 06:43:12AM -0400, Victor Subervi wrote:
> > Hi:
> > I have the following python code:
> > import os
> > os.system("mysqldump -u root -pPASSWORD --opt spreadsheets > dump.sql")
> > This nicely creates the file...but the file is empty! The database exists
> > and has lots of data, I double-checked it. If there is nothing wrong with
> my
> > code, is there some way to do the same thing from within MySQL? Can I at
> > least print everything to screen and copy it? Where would I find my
> database
> > in Windoze?
>
> Are you sure the password you entered is correct? I tested the code and
> it worked fine for me. However, when I used an incorrect password, it
> returned an error and did create an empty file, just as you describe.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On 9/1/2009 9:22 PM r said... On Sep 1, 10:16 pm, Steven D'Aprano Took me two weeks of elapsed time and around 30 hours of effort to remove those suckers from the machine. Now I run Linux, behind two firewalls. Takes me less than one hour to rebuild my system If that's your job (as it's sometimes mine) then that sounds about right. Otherwise, you must have a lot of practice rebuilding! Emile -- http://mail.python.org/mailman/listinfo/python-list
Issue with writelines
I've written this program that has been working fine until today.
Can't work out why it stopped working. The program pulls a list from
an xls file, inserts each item from the list into a repeating string,
that then concatenates the repeating string and writes it to a text
file. It has worked fine until today, and now for some reason, it
stops after 30 items in my list. I also just tried another list, and
that one stopped after 70 items. Perhaps someone could take a look?
Here's the file followed by the traceback:
import xlrd
import win32clipboard
def program_uno():
ofile = open(r"C:\Query\DQLVault.txt", "w")
book = xlrd.open_workbook(r"C:\DocLoader\MCL_Drawing and Legacy
Docloader Sheet.xls")
sh = book.sheet_by_index(0)
e = sh.cell_value(1, 0)
a = sh.col_values(0, start_rowx=2, end_rowx=200)
b = r'%' + e
c = r'%Master-V%'
y = r"SELECT object_name, bp_master_date, revision,
bp_revision_date, bp_unit_no, r_version_label, r_object_id,
r_lock_owner, r_content_size, a_content_type, r_modify_date,
r_object_type, r_link_cnt, r_assembled_from_id, r_has_frzn_assembly,
a_is_hidden, i_is_replica, i_is_reference, r_is_virtual_doc,
i_chronicle_id, i_folder_id FROM mcl_engineer (ALL) WHERE (((upper
(object_name) like upper('%s')) and (any upper(r_version_label) like
upper('%s'))" %(b, c)
w = r")) ORDER BY object_name ASC, r_object_id DESC, i_position
DESC"
ofile.writelines(y)
for x in a:
d = r'%' + x
z = r" or (upper(object_name) like upper('%s')) and (any upper
(r_version_label) like upper('%s'))" %(d, c)
f = ofile.writelines(z)
ofile.writelines(w)
def copy_text():
ifile = open(r"C:\Query\DQLVault.txt", "r")
text = ifile.read()
ifile.close()
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()
program_uno()
copy_text()
Traceback:
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Query\DQL Vault Revision Check.py", line 34, in
program_uno()
File "C:\Query\DQL Vault Revision Check.py", line 20, in program_uno
f = ofile.writelines(z)
TypeError: writelines() argument must be a sequence of strings
--
http://mail.python.org/mailman/listinfo/python-list
Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)
Sverker Nilsson wrote: Sverker Nilsson wrote: It reads one Stat object at a time and wants to report something when there is no more to be read from the file. Hmm, am I right in thinking the above can more nicely be written as: >>> from guppy import hpy >>> h = hpy() >>> f = open(r'your.hpy') >>> sets = [] >>> for s in iter(h.load(f)): sets.append(s) ... The above iterates over one Stat object returned by h.load(f). I assume you want to iterate over all the objects loaded. I dont know guppy, but if h.load(f) raises StopIteration upon eof, as seems implied by your proposal, then something like the following would work. sets.extend(h.load(f) for _ in xrange(1e9)) -- http://mail.python.org/mailman/listinfo/python-list
Simple addition to random module - Student's t
While the random module allows one to generate randome numbers with a variety of distributions, some useful distributions are omitted - the Student's t being among them. This distribution is easily derived from the normal distribution and the chi-squared distribution (which in turn is a special case of the gamma distribution). I edited and tested a routine to generate random variables with a Student's t distribution that I found on http://www.johndcook.com/python_student_t_rng.html, which has one bug - there is an extra factor of two in y. The corrected and tested code follows - how does one go about getting this incorporated into random so that the entire community can beneffit from it? Sincerely Thomas Philips def student_t(df): # df is the number of degrees of freedom if df < 2 or int(df) != df: raise ValueError, 'student_tvariate: df must be a integer > 1' x = random.gauss(0, 1) y = random.gammavariate(df/2.0, 2) return x / (math.sqrt(y/df)) References: 1. Student's t distribution, including relationship to normal and chi- squared distributions: http://en.wikipedia.org/wiki/Student's_t-distribution 2. Chi-squared distribution, including relationship to Gamma distribution: http://en.wikipedia.org/wiki/Chi-square_distribution 3. John Cook's original version (with the extra factor of 2): http://www.johndcook.com/python_student_t_rng.html -- http://mail.python.org/mailman/listinfo/python-list
Re: win32ui DLL Load Failed
On Sep 1, 12:14 am, Gregor Horvath wrote: > Am Mon, 31 Aug 2009 12:43:04 -0700 (PDT) > schriebMikeC: > > > I have a python executable that's failing to load on a user's machine > > running Windows XP. My developer machine is also running Windows XP. I > > have determined that it is failing when it attempts to load win32ui. > > > I have Python 2.6 on my developer machine and am using the pywin > > support (Mark Hammonds???) for Python 2.6. > > Try to install: > > http://www.microsoft.com/downloads/details.aspx?familyid=9b2da534-3e0... > > 2.6 is linked against VS8 dlls, which are missing on some machines. > > -- > Gregor Gregor, This solved my problem. Thank you so much! Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On 2009-09-02, Terry Reedy wrote: > Steven D'Aprano wrote: > >>> I have read more that one person advocating >>> leaving one's wi-fi base open for anyone to use as the 'neighborly' >>> thing to do. >> >> That's a different kettle of fish. You don't do anybody any >> harm by paying for Internet access for your neighbours (and >> anyone driving down the street with a laptop and wi-fi). > > Unless the 'neighbor' is your friendly local spam or malware > merchant ;-) A spam/malware merchange who can't afford/arrange other internet access? How is net access on the critical path? -- Grant Edwards grante Yow! I haven't been married at in over six years, but we visi.comhad sexual counseling every day from Oral Roberts!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On 2009-09-02, Steven D'Aprano wrote: > On Wed, 02 Sep 2009 02:16:27 -0400, Terry Reedy wrote: > >> Steven D'Aprano wrote: >> I have read more that one person advocating leaving one's wi-fi base open for anyone to use as the 'neighborly' thing to do. >>> >>> That's a different kettle of fish. You don't do anybody any harm by >>> paying for Internet access for your neighbours (and anyone driving down >>> the street with a laptop and wi-fi). >> >> Unless the 'neighbor' is your friendly local spam or malware >> merchant ;-) > > Since they're sending spam through your account, it's the same > as you sending the spam, and you're responsible for it. Nobody said anything about allowing anybody to "send spam through your account". -- Grant Edwards grante Yow! ! Everybody out of at the GENETIC POOL! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
Gabriel Genellina wrote: > Looks like we all will have to learn mandarin! A nice language but with a > high entrance barrier for western people. It will pay off in the long run. Problem for me: it seems most people in Toronto speak Cantonese. That's just something I'll have to deal with. Wrote a little 3-in-a-row game to get familiar with Chinese characters. Astonished at how Chinese-ready Python 2.5 already is. Collecting characters from web sites and pasting them in to literals in the program source just works. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
On 9/2/2009 3:43 AM Victor Subervi said...
Hi:
I have the following python code:
import os
os.system("mysqldump -u root -pPASSWORD --opt spreadsheets > dump.sql")
First, test this at the system command line -- you'll likely get an
empty file there as well, so calling from within python simply does the
same.
Then read the mysqldump docs for the command arguments and supply the
database name...
Emile
This nicely creates the file...but the file is empty! The database exists
and has lots of data, I double-checked it. If there is nothing wrong with my
code, is there some way to do the same thing from within MySQL? Can I at
least print everything to screen and copy it? Where would I find my database
in Windoze?
TIA,
Victor
--
http://mail.python.org/mailman/listinfo/python-list
pickling question
When you define a class in a script, and then pickle instances of that class in
the same script and store them to disk, you can't load that pickle in another
script. At least not the straightforward way
[pickle.load(file('somefile.pickle'))]. If you try it, you get an
AttributeError during the unpickling operation.
There is no problem, of course, if the class is defined in a module which is
imported by the pickling script. pickle.load(file('somefile.pickle')) then
works.
Rather than provide specific examples here, there's a blog post from 2005 that
discusses this issue in depth and presents the problem very well:
http://stefaanlippens.net/pickleproblem. (I tested in Python 2.6 yesterday and
the same issue persists.)
Questions:
1) Does this have to be the case, or is it a design problem with pickles that
should be remedied?
2) Is there an easier way around it than moving the class definition to a
separate module? The blog post I point to above suggests putting "__module__ =
os.path.splitext(os.path.basename(__file__))[0]" into the class definiton, but
that's not working in my testing because when I do that, the pickling operation
fails. Is there something else that can be done?
This is obviously not a huge problem. Substantial classes should usually be
defined in a separate module anyway. But sometimes it makes sense for a script
to define a really simple, small class to hold some data, and needing to create
a separate module just to contain such a class can be a little annoying.
--
Gary Robinson
CTO
Emergent Music, LLC
personal email: [email protected]
work email: [email protected]
Company: http://www.flyfi.com
Blog:http://www.garyrobinson.net
--
http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 2:51 pm, Thomas Philips wrote: > While the random module allows one to generate randome numbers with a > variety of distributions, some useful distributions are omitted - the > Student's t being among them. This distribution is easily derived from > the normal distribution and the chi-squared distribution (which in > turn is a special case of the gamma distribution). I edited and tested > a routine to generate random variables with a Student's t distribution > that I found onhttp://www.johndcook.com/python_student_t_rng.html, > which has one bug - there is an extra factor of two in y. The > corrected and tested code follows - how does one go about getting this > incorporated into random so that the entire community can beneffit > from it? To get this into core Python, you'd usually submit a feature request at http://bugs.python.org. To maximize the chances of the feature being accepted, provide unit tests and documentation along with the code. There's a lot of good information about how the Python development process works at http://www.python.org/dev; see especially http://www.python.org/dev/contributing/. Alternatively, you might also consider submitting something to the Python package index, http://pypi.python.org/pypi, or posting this as a recipe at http://code.activestate.com/recipes/langs/python/ -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Entry Level Python Jobs
I am a self-taught Python programmer with a liberal arts degree (Cross- cultural studies). I have been programming for several years now and would like to get a job as a python programmer. Unfortunately most of the job posts I have seen are for CS Majors or people with experience. Is there a place I can look for job posts for entry level positions requiring no experience? For the hiring managers, if the job post said "CS Major" in the requirements, would you consider a liberal arts major at all? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
On Wed, Sep 02, 2009 at 08:43:22AM -0400, Victor Subervi wrote: > > Obviously I'm sure. It created the file. But the file was blank. How can I > do a mysqldump in mysql itself? > As I said, I only got a blank file when the actual command itself failed. How do you dump the MySQL database itself without using Python? Just run the 'mysqldump' command from the prompt. Is that what you are asking? Are you running this on Windows? What OS? You do have the 'mysqldump' command available from the shell prompt and in your path, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
Not sure how to test it at the command line as you recommend; however, I
most certainly did supply the db name. I most certainly did check the docs.
I also looked at code I had previously written that worked. So I'm stumped!
Is there any way to print it out to screen or (better yet) print to screen
in mysql itself?
TIA,
V
On Wed, Sep 2, 2009 at 10:18 AM, Emile van Sebille wrote:
> On 9/2/2009 3:43 AM Victor Subervi said...
>
>> Hi:
>> I have the following python code:
>> import os
>> os.system("mysqldump -u root -pPASSWORD --opt spreadsheets > dump.sql")
>>
>
> First, test this at the system command line -- you'll likely get an empty
> file there as well, so calling from within python simply does the same.
>
> Then read the mysqldump docs for the command arguments and supply the
> database name...
>
> Emile
>
>
> This nicely creates the file...but the file is empty! The database exists
>> and has lots of data, I double-checked it. If there is nothing wrong with
>> my
>> code, is there some way to do the same thing from within MySQL? Can I at
>> least print everything to screen and copy it? Where would I find my
>> database
>> in Windoze?
>> TIA,
>> Victor
>>
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
On Sep 2, 10:31 am, JonathanB wrote: > I am a self-taught Python programmer with a liberal arts degree (Cross- > cultural studies). I have been programming for several years now and > would like to get a job as a python programmer. Unfortunately most of > the job posts I have seen are for CS Majors or people with experience. > > Is there a place I can look for job posts for entry level positions > requiring no experience? For the hiring managers, if the job post said > "CS Major" in the requirements, would you consider a liberal arts > major at all? Have you thought about getting involved with the Python core development. Not a paying position, but may lead you to some good connections, and i can't think of a better place to prove yourself than that ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: pickling question
On Sep 2, 7:06 am, Gary Robinson wrote:
> When you define a class in a script, and then pickle
> instances of that class in the same script and store
> them to disk, you can't load that pickle in another
> script. At least not the straightforward way
> [pickle.load(file('somefile.pickle'))]. If you try it,
> you get an AttributeError during the unpickling
> operation.
It's because when you pickle from the script it's defined in the
module is called '__main__'. When import the script file as a Python
module from another script, the module is called 'script' or whatever
the filename is. It's just the way importing works.
> There is no problem, of course, if the class is defined
> in a module which is imported by the pickling script.
> pickle.load(file('somefile.pickle')) then works.
>
> Rather than provide specific examples here, there's a
> blog post from 2005 that discusses this issue in depth
> and presents the problem very
> well:http://stefaanlippens.net/pickleproblem. (I tested
> in Python 2.6 yesterday and the same issue persists.)
Actually that page kind of glosses over the real issue. But never
mind that.
> Questions:
>
> 1) Does this have to be the case, or is it a design
> problem with pickles that should be remedied?
It won't be remedied for the just sake of pickling. However, I'm
starting to think the underlying issue should be. It's by far the
most confusing aspect of Python.
> 2) Is there an easier way around it than moving the
> class definition to a separate module? The blog post I
> point to above suggests putting "__module__ =
> os.path.splitext(os.path.basename(__file__))[0]" into
> the class definiton, but that's not working in my
> testing because when I do that, the pickling operation
> fails. Is there something else that can be done?
>
> This is obviously not a huge problem. Substantial
> classes should usually be defined in a separate module
> anyway. But sometimes it makes sense for a script to
> define a really simple, small class to hold some data,
> and needing to create a separate module just to contain
> such a class can be a little annoying.
My general recommendation is not to mix scripts a modules unless you
an expert on Python importing. A file should be either a script or a
module, not both.
Warning: It's really hard to be expert on Python importing. I've seen
confusion about how imports work even from some very smart people on
this list (most notably, from people who mistakenly believe that PEP
328 is a fix for your issue). Python importing is the biggest wart in
the language by far.
However, if you insist, I will tell you a workaround you can use. At
the very top of your script put the following lines (replacing script
with the module's filename minus the .py):
import sys
if __name__ == '__main__':
ismain = True
__name__ = 'script'
sys.modules['script'] = sys.modules['__main__']
else:
ismain = False
Then use "if ismain" instead of "if __name__ == '__main__'" to
determine if you are running from a script. This has to come before
any class definitions or it won't work. This effectively renames the
script's __main__ module to what it would have been if it had been
imported. Then proceed with pickling as usual.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
On Sep 2, 2009, at 11:48 AM, r wrote: On Sep 2, 10:31 am, JonathanB wrote: I am a self-taught Python programmer with a liberal arts degree (Cross- cultural studies). I have been programming for several years now and would like to get a job as a python programmer. Unfortunately most of the job posts I have seen are for CS Majors or people with experience. Is there a place I can look for job posts for entry level positions requiring no experience? For the hiring managers, if the job post said "CS Major" in the requirements, would you consider a liberal arts major at all? Have you thought about getting involved with the Python core development. Not a paying position, but may lead you to some good connections, and i can't think of a better place to prove yourself than that ;-) Or instead of diving into the Python core which might be pretty heavy stuff, create some open source code -- a game, a calculator, a music generator, an app to automatically download weather maps, etc. Whatever tickles your fancy. If you're willing to stand on your merits (and it sounds like you are), you can point people to where your code is hosted and say, "I wrote that". Anyway, it's something to do in between hitting refresh on http://www.python.org/community/jobs/ Good luck to you Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 2:51 pm, Thomas Philips wrote: > def student_t(df): # df is the number of degrees of freedom > if df < 2 or int(df) != df: > raise ValueError, 'student_tvariate: df must be a integer > 1' By the way, why do you exclude the possibility df=1 here? -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
JonathanB writes: > I am a self-taught Python programmer with a liberal arts degree (Cross- > cultural studies) > Is there a place I can look for job posts for entry level positions > requiring no experience? For the hiring managers, if the job post said > "CS Major" in the requirements, would you consider a liberal arts > major at all? I think in the current economy there are not many entry level positions requiring no experience, except for internships and that sort of thing. Also there are some jobs which really do call for a CS major or someone of equivalent background. Often though, pure technical background doesn't matter as much as inventiveness and the ability to make things happen, which is more a matter of personality than training. I don't know what cross-cultural studies is, but I could imagine assignments (e.g. internationalizing the user interface of a program or web site) where someone with that background could work out fine. Basically I think for pure software development openings, you may be difficult to place, but there's lots of other types of openings where the primary task is something other than programming and yet incidental amounts of programming are involved. For those, you'd have a much better shot. One thing that can certainly help is to have a portfolio of code you've written for personal or academic projects or whatever. Where I work we're in the process of interviewing a guy who is some kind of artist, who has used Python in some pretty cool art projects. He has a bunch of code on his web site that were very helpful in getting an impression of his capabilities. -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
Philip Semanchuk wrote: On Sep 2, 2009, at 11:48 AM, r wrote: On Sep 2, 10:31 am, JonathanB wrote: I am a self-taught Python programmer with a liberal arts degree (Cross- cultural studies). I have been programming for several years now and would like to get a job as a python programmer. Unfortunately most of the job posts I have seen are for CS Majors or people with experience. Is there a place I can look for job posts for entry level positions requiring no experience? For the hiring managers, if the job post said "CS Major" in the requirements, would you consider a liberal arts major at all? Have you thought about getting involved with the Python core development. Not a paying position, but may lead you to some good connections, and i can't think of a better place to prove yourself than that ;-) Or instead of diving into the Python core which might be pretty heavy stuff, create some open source code -- a game, a calculator, a music generator, an app to automatically download weather maps, etc. Whatever tickles your fancy. If you're willing to stand on your merits (and it sounds like you are), you can point people to where your code is hosted and say, "I wrote that". Anyway, it's something to do in between hitting refresh on http://www.python.org/community/jobs/ Good luck to you Philip Philip is right -- I would consider a non-CS major, but then you'd get round-filed for the no experience. Write something, or better yet, a few smallish somethings and a medium something, and then you can claim experience. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
Ok, so what I'm hearing is "Get a code portfolio together and watch the job board on python.org." Thanks for the advice! I've been watching the python job board 3-4 times a week and I've been working my way through the Project Euler problems in my free time. I also have a trade generator that I wrote up to support a Traveller game I was running a while back, but that code is old (the first non- trivial program I ever wrote) and really fairly buggy. The user interface is basically an infinite recursion that I sys.exit() out of when I'm through, which means the code slows considerably as you do more stuff in it because each trip back to the main menu is a recursive call to the main() function. Hey, I was young and naive. I'm working on cleaning it up right now. Any other tips? -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 12:28 pm, Mark Dickinson wrote: > On Sep 2, 2:51 pm, Thomas Philips wrote: > > > def student_t(df): # df is the number of degrees of freedom > > if df < 2 or int(df) != df: > > raise ValueError, 'student_tvariate: df must be a integer > 1' > > By the way, why do you exclude the possibility df=1 here? > > -- > Mark I exclude df=1 hereBecause the variance is then infinite (in fact, the distribution is then Cauchy). That said, your point is well taken; allowing df=1 makes the Cauchy distribution available to users of random, in much the same way as the Gamma makes the Chi-squared available. Here's the revised code: def student_tvariate(df): # df is the number of degrees of freedom if df < 1 or int(df) != df: raise ValueError, 'student_tvariate: df must be a positive integer' x = random.gauss(0, 1) y = random.gammavariate(df/2.0, 2) return x / (math.sqrt(y/df)) I'll follow your suggestion, add in documentation and submit it to bugs.python.com. Thanks for your guidance. Thomas Philips -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
In article , JonathanB wrote: > >I am a self-taught Python programmer with a liberal arts degree (Cross- >cultural studies). I have been programming for several years now and >would like to get a job as a python programmer. Unfortunately most of >the job posts I have seen are for CS Majors or people with experience. > >Is there a place I can look for job posts for entry level positions >requiring no experience? For the hiring managers, if the job post said >"CS Major" in the requirements, would you consider a liberal arts >major at all? You should also look into finding e.g. a tech support job at a company using Python. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet -- http://mail.python.org/mailman/listinfo/python-list
Re: pickling question
On 02:06 pm, [email protected] wrote: When you define a class in a script, and then pickle instances of that class in the same script and store them to disk, you can't load that pickle in another script. At least not the straightforward way [pickle.load(file('somefile.pickle'))]. If you try it, you get an AttributeError during the unpickling operation. There is no problem, of course, if the class is defined in a module which is imported by the pickling script. pickle.load(file('somefile.pickle')) then works. Rather than provide specific examples here, there's a blog post from 2005 that discusses this issue in depth and presents the problem very well: http://stefaanlippens.net/pickleproblem. (I tested in Python 2.6 yesterday and the same issue persists.) Questions: 1) Does this have to be the case, or is it a design problem with pickles that should be remedied? 2) Is there an easier way around it than moving the class definition to a separate module? The blog post I point to above suggests putting "__module__ = os.path.splitext(os.path.basename(__file__))[0]" into the class definiton, but that's not working in my testing because when I do that, the pickling operation fails. Is there something else that can be done? I described another solution here: http://jcalderone.livejournal.com/45604.html Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
website feedback to where?
Greetings. A little new to python here, but... on this page http://docs.python.org/3.1/tutorial/introduction.html some of the "text" examples are [incorrectly] color formatted. I assume this a bug reportable to bugs.python.org? Thanks! -r -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
On Sep 2, 11:31 am, JonathanB wrote: > For the hiring managers, if the job post said > "CS Major" in the requirements, would you consider a liberal arts > major at all? I got my English Writing degree in 1990, and I have been a software engineer ever since. Landing the first job was very difficult, but it gave me the foundation of experience that allowed me to circumvent the "CS-degree or equivalent" requirement on every job that I have had since. If you do choose to pursue software development as a career, you'll be shocked at how many of your fellow liberal arts degree holders are doing the same. It will be a hard road. You will have to overcome significant obstacles. You will do boring, tedious work. You will find out what it really means to pay one's dues. You will also, perchance, succeed and find happiness in a fulfilling career. I think that Python is an outstanding foundation for learning programming, but I would advise you to branch out as quickly as possible. I imagine that saying so won't endear me to anyone here, but in good conscience, I have to recommend C# and the .NET framework; it has lead me to continual and well-paying employment for many, many years now. Also, put together an on-line portfolio of code, preferably composed of complete and useful programs. Actually seeing well- written, well-documented code can go a long way towards getting you in the door for an interview. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 1:03 pm, Thomas Philips wrote: > On Sep 2, 12:28 pm, Mark Dickinson wrote: > > > On Sep 2, 2:51 pm, Thomas Philips wrote: > > > > def student_t(df): # df is the number of degrees of freedom > > > if df < 2 or int(df) != df: > > > raise ValueError, 'student_tvariate: df must be a integer > 1' > > > By the way, why do you exclude the possibility df=1 here? > > > -- > > Mark > > I exclude df=1 hereBecause the variance is then infinite (in fact, the > distribution is then Cauchy). That said, your point is well taken; > allowing df=1 makes the Cauchy distribution available to users of > random, in much the same way as the Gamma makes the Chi-squared > available. Here's the revised code: > > def student_tvariate(df): # df is the number of degrees of > freedom > if df < 1 or int(df) != df: > raise ValueError, 'student_tvariate: df must be a positive > integer' > > x = random.gauss(0, 1) > y = random.gammavariate(df/2.0, 2) > > return x / (math.sqrt(y/df)) > > I'll follow your suggestion, add in documentation and submit it to > bugs.python.com. Thanks for your guidance. > > Thomas Philips Mark, I mis-spoke - the variance is infinite when df=2 (the variance is df/ (df-2), and you get the Cauchy when df=2. So I'm going to eat humble pie and go back to def student_tvariate(df): # df is the number of degrees of freedom if df < 2 or int(df) != df: raise ValueError, 'student_tvariate: df must be a integer > 1' x = random.gauss(0, 1) y = random.gammavariate(df/2.0, 2) return x / (math.sqrt(y/df)) I made the mistake because the denominator is equivalent to the square root of the sample variance of df normal observations, which in turn has df-1 degrees of freedom...Oh well, I think it's much easier to apologize than to rationalize my error Sincerely Tom -- http://mail.python.org/mailman/listinfo/python-list
ctypes WNetGetUniversalNameW
Hello,
I'm trying to call WNetGetUniversalNameW via the ctypes module but I'm
only causing the interpreter to crash. Unfortunately I don't have much
experience with the ctypes module and I'm still trying to figure it
out. I've searched for a solution to no avail. My confusion is
centered around the LPVOID buffer parameter and how this should be
created/used. Any help is appreciated.
# DWORD WNetGetUniversalName(
# __in LPCTSTR lpLocalPath,
# __in DWORD dwInfoLevel,
# __outLPVOID lpBuffer,
# __inout LPDWORD lpBufferSize
# );
import ctypes, win32netcon
LPDWORD = ctypes.POINTER(DWORD)
class UniversalNameInfo(ctypes.Structure):
__fields__ = [("lpUniversalName", LPCWSTR)]
WNetGetUniversalNameW = ctypes.windll.mpr.WNetGetUniversalNameW
path = LPCWSTR('Y:')
level = DWORD(win32netcon.UNIVERSAL_NAME_INFO_LEVEL)
buffer_len = LPDWORD(DWORD(1024))
uni_struct = UniversalNameInfo()
ret = WNetGetUniversalNameW(path, level, uni_struct, buffer_len)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On Wed, 02 Sep 2009 06:20:39 -0700, Emile van Sebille wrote: > On 9/1/2009 9:22 PM r said... >> On Sep 1, 10:16 pm, Steven D'Aprano >>> Took me two weeks of elapsed time and around 30 hours of effort to >>> remove those suckers from the machine. Now I run Linux, behind two >>> firewalls. >> >> Takes me less than one hour to rebuild my system > > If that's your job (as it's sometimes mine) then that sounds about > right. Otherwise, you must have a lot of practice rebuilding! I could have nuked the machine and rebuilt it from scratch, but I couldn't find my WinXP original media. Besides, when I started the process, I had no idea it would take so long. I learned one thing though. System Restore sounds like a good idea, but in my experience it's only good for restoring malware when you reboot. (I won't tell you how many times I deleted the same spyware apps before I worked out what was happening. Grrr arrg.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: evolution [was Re: An assessment of the Unicode standard]
On Sep 2, 4:41 am, Steven D'Aprano wrote: (snip) > > No evolution awards those that benefit evolution. You make it seem as > > evolution is some loving mother hen, quite the contrary! Evolution is > > selfish, greedy, and sometimes evil. And it will endure all of us... > > > remember the old cliche "Nice guys finish last"? > > This is Not Even Wrong. Evolution isn't a *thing*, it is a *process*. > Nothing exists to "benefit evolution", that's like saying that horses > have long legs to "benefit running" or people have lungs to "benefit > breathing". Well horses do have long and well evolved legs for running and humans lungs for breathing, and they have them because it benefits them which in turn benefits evolution. the buck stops with evolution. > "R" is utterly confused if he thinks species live or die according to > because they're benefiting evolution. Species live or die according to > whether or not they reproduce, Dear God i hate the current "progress" of evolution if reproduction guaranteed survival. I think it is just a "wee" bit more complicated than that Steven. *wink* > (This sort of nonsense, anthropomorphizing the process of evolution, > seems to be unique to those on the right-wing of politics. Go figure.) Uh? let's not go there. Leave politics corrupting influence out of this. > Steve (the other Steve) is right -- species which are incapable of > dealing with the complexity and dynamism of the world are doomed to > extinction. Biologists have a word for stasis: "dead". The most vigorous, > lively ecosystems are those that are complex, like rain forests (what > used to be called "jungles" when I was a lad), coral reefs and mangroves. > Messy, complicated, complex ecosystems are successful because they are > resilient to damage -- a plague comes along and even if it kills off > every individual of one species of fruit, there are a thousand different > species unharmed. > > The sort of monoculture which "r" sings the praises of are fragile and > brittle. Look at the Cavendish banana, nearly extinct because a disease > is wiping the plants out, and there's not enough genetic variability in > it to survive. (Fortunately there are dozens of varieties of bananas, so > when the Cavendish becomes extinct, we'll still have bananas.) You cannot draw parallels between bio diversity and language diversity. Bio diversity is fundamental to all species survival, even a virus. I am quite sure that the adoption of Universal World language will not usher in the apocalypse for human kind, quite the contrary! Ok a Jew, a Catholic Priest and a Chinese man walk into a bar Now if the bar suddenly catches fire and only one of them notices, how should this person convey the danger to the others. Well he could jump- up-and-down-yelling-oh!-oh!-oh!-with-arms-failing-in-the-air, but i think human evolution has presented a far more elegant way to communicate than that of the chimpanzee. > Or the Irish Potato Famine: millions of Irish dead from famine because > 90% of their food intake came from a *single* source, potatoes, which in > turn came from not just a single variety but just a handful of closely > related individuals. OMG! human kind will be utterly wiped out by the universal language. Somebody please jump-up-and-down-with-flailing-arms we must warn everyone of this impending doom before it is too late! (snip: more political innuendo) > As for the idea "nice guys finish last", that's a ridiculous over- > simplification. Vampire bats share their food with other vampire bats who > otherwise would be hungry. ...could be they are fatting them up for the kill! > Remoras stick to sharks, who carry them around > for years without eating them. ...Well yes sharks share a personality trait with cab drivers but...? And i wonder if they really *know* they are back there? Sharks aren't exactly evolutions shining jewel. > There's those little birds which climb > into the mouths of crocodiles to clean their teeth while the crocodile > sits patiently with it's mouth wide open. ...Hmm, i have thought about clamping down hard while my dentist pokes around with his fingers in there. But who then would clean my teeth? And it could be that those crocs are just slightly vain? > Wolves and wild dogs and hyenas > hunt cooperatively. Baboons and chimpanzees form alliances. Penguins > huddle together through the freezing months of darkness, and although the > winds are so cold that the penguins on the outside would freeze to death, > few of them do, because they all take their share of time in the centre. ...birds of a feather flock together! > Monkeys cry out warnings when they see a leopard or a hawk, even though > it puts them personally at risk. Meercats post sentries, who expose > themselves to danger to protect the rest of the colony. ...they could be expendable to the community! > And the most successful mammal on the planet, more successful than any > other large animal, is also the most cooperative,
Re: Entry Level Python Jobs
On Wed, 2009-09-02 at 08:31 -0700, JonathanB wrote: > I am a self-taught Python programmer with a liberal arts degree > (Cross-cultural studies). I have been programming for several years > now and would like to get a job as a python programmer. Unfortunately > most of the job posts I have seen are for CS Majors or people with > experience. > > Is there a place I can look for job posts for entry level positions > requiring no experience? For the hiring managers, if the job post said > "CS Major" in the requirements, would you consider a liberal arts > major at all? Definately not without any experience - but "experience" doesn't have to come from paid work - coding as a hobby in your free time is what's made all the best developers I know. Some things I personally would expect (and find more important than a CS background) - in order of importance: * Experience (e.g. open source / hobby projects / work) - several years worth. * Problem solving ability * A good comprehension of C, machine code, or something where you have to care about pointers/references. * Basic maths skills. Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
I am running this on Windoze. I do not use the mysql db without python. I'm just building something for a client. I tried running the mysqldump command from the python prompt. Didn't know I could do that :) It tells me "mysqldump is not defined" :( V On Wed, Sep 2, 2009 at 11:48 AM, Nitebirdz wrote: > On Wed, Sep 02, 2009 at 08:43:22AM -0400, Victor Subervi wrote: > > > > Obviously I'm sure. It created the file. But the file was blank. How can > I > > do a mysqldump in mysql itself? > > > > As I said, I only got a blank file when the actual command itself > failed. How do you dump the MySQL database itself without using Python? > Just run the 'mysqldump' command from the prompt. Is that what you are > asking? > > Are you running this on Windows? What OS? You do have the 'mysqldump' > command available from the shell prompt and in your path, right? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On 2009-09-02 11:28 AM, Mark Dickinson wrote: On Sep 2, 2:51 pm, Thomas Philips wrote: def student_t(df): # df is the number of degrees of freedom if df< 2 or int(df) != df: raise ValueError, 'student_tvariate: df must be a integer> 1' By the way, why do you exclude the possibility df=1 here? Similarly, requiring df to be an integer is extraneous. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue with writelines
On Wed, Sep 2, 2009 at 6:50 PM, LeeRisq wrote:
> I've written this program that has been working fine until today.
> Can't work out why it stopped working. The program pulls a list from
> an xls file, inserts each item from the list into a repeating string,
> that then concatenates the repeating string and writes it to a text
> file. It has worked fine until today, and now for some reason, it
> stops after 30 items in my list. I also just tried another list, and
> that one stopped after 70 items. Perhaps someone could take a look?
>
> Here's the file followed by the traceback:
>
> import xlrd
> import win32clipboard
>
>
>
> def program_uno():
>ofile = open(r"C:\Query\DQLVault.txt", "w")
>book = xlrd.open_workbook(r"C:\DocLoader\MCL_Drawing and Legacy
> Docloader Sheet.xls")
>sh = book.sheet_by_index(0)
>e = sh.cell_value(1, 0)
>a = sh.col_values(0, start_rowx=2, end_rowx=200)
>b = r'%' + e
>c = r'%Master-V%'
>y = r"SELECT object_name, bp_master_date, revision,
> bp_revision_date, bp_unit_no, r_version_label, r_object_id,
> r_lock_owner, r_content_size, a_content_type, r_modify_date,
> r_object_type, r_link_cnt, r_assembled_from_id, r_has_frzn_assembly,
> a_is_hidden, i_is_replica, i_is_reference, r_is_virtual_doc,
> i_chronicle_id, i_folder_id FROM mcl_engineer (ALL) WHERE (((upper
> (object_name) like upper('%s')) and (any upper(r_version_label) like
> upper('%s'))" %(b, c)
>
>w = r")) ORDER BY object_name ASC, r_object_id DESC, i_position
> DESC"
>
>ofile.writelines(y)
>for x in a:
>d = r'%' + x
>z = r" or (upper(object_name) like upper('%s')) and (any upper
> (r_version_label) like upper('%s'))" %(d, c)
>f = ofile.writelines(z)
>ofile.writelines(w)
>
>
> def copy_text():
>ifile = open(r"C:\Query\DQLVault.txt", "r")
>text = ifile.read()
>ifile.close()
>
>win32clipboard.OpenClipboard()
>win32clipboard.EmptyClipboard()
>win32clipboard.SetClipboardText(text)
>win32clipboard.CloseClipboard()
>
> program_uno()
> copy_text()
>
> Traceback:
>
> File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework
> \scriptutils.py", line 310, in RunScript
>exec codeObject in __main__.__dict__
> File "C:\Query\DQL Vault Revision Check.py", line 34, in
>program_uno()
> File "C:\Query\DQL Vault Revision Check.py", line 20, in program_uno
>f = ofile.writelines(z)
> TypeError: writelines() argument must be a sequence of strings
>
why can't you print/analyse the 'z ' value on except block.
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Yours,
S.Selvam
--
http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Sep 2)
QOTW: "I like how being very friendly means calling people after a guy who tried to blow up the English Parliament." - Carl Banks http://groups.google.com/group/comp.lang.python/browse_thread/thread/7a190c24d8025bb4 unichr/ord cannot handle characters outside the BMP in a narrow build: http://groups.google.com/group/comp.lang.python/t/2fe770303f1d85ea/ How to determine if a class implements a particular interface: http://groups.google.com/group/comp.lang.python/t/27ea61dd2aaa0fcb/ Igor Novikov provides a lovely small pure-Python extension to manage ARGB cursors in Tkinter. http://tkinter.unpy.net/wiki/tkXcursor Why does `some_integer += 1` create a new integer object instead of incrementing the current value? http://groups.google.com/group/comp.lang.python/t/25b921e3b00ec2ae/ Iterating and mutating a list from two or more threads: http://groups.google.com/group/comp.lang.python/t/b19381a806007f4d/ Mapping message identifiers to methods: http://groups.google.com/group/comp.lang.python/t/8f7f1771945b4add/ A class definition doesn't introduce a new lexical scope - and that's a Good Thing [long thread]: http://groups.google.com/group/comp.lang.python/t/2cd187fa256744fe/ A clean way of adding directories to the module search path: http://groups.google.com/group/comp.lang.python/t/9052cc623088bdb2/ Recipe: convert an existing module into a package or sub-package http://groups.google.com/group/comp.lang.python/t/9919cf2a60722344/ Tools for designing professional-looking applications for Windows: http://groups.google.com/group/comp.lang.python/t/d22dcd394ab08333/ The basics for doing Web applications in Python: http://groups.google.com/group/comp.lang.python/t/1176ea4e6814f466/ What CAN'T be done in Python? http://groups.google.com/group/comp.lang.python/t/a368e85aa85ab436/ Favorite debugging tools? http://groups.google.com/group/comp.lang.python/t/1efb7b97d5d94d9b/ In 3.1, print() requires the terminal to be correctly configured with respect to locale settings: http://groups.google.com/group/comp.lang.python/t/8e666bb7eae9c859/ Idea: expand the for statement to accept additional, nested 'for's and an '= if' clause: http://groups.google.com/group/comp.lang.python/t/83b1d70457345877/ Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http:
Re: Problem w/ mysqldump
I tried running the mysqldump command from the python prompt I think you were being asked to try running it from the command prompt (cmd.exe) -- it won't work from the Python prompt, of course. On Wed, 02 Sep 2009 10:50:55 -0700, Victor Subervi wrote: I am running this on Windoze. I do not use the mysql db without python. I'm just building something for a client. I tried running the mysqldump command from the python prompt. Didn't know I could do that :) It tells me "mysqldump is not defined" :( V On Wed, Sep 2, 2009 at 11:48 AM, Nitebirdz wrote: On Wed, Sep 02, 2009 at 08:43:22AM -0400, Victor Subervi wrote: > > Obviously I'm sure. It created the file. But the file was blank. How can I > do a mysqldump in mysql itself? > As I said, I only got a blank file when the actual command itself failed. How do you dump the MySQL database itself without using Python? Just run the 'mysqldump' command from the prompt. Is that what you are asking? Are you running this on Windows? What OS? You do have the 'mysqldump' command available from the shell prompt and in your path, right? -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on the Web
On Aug 26, 4:17 am, alex23 wrote: > Frameworks created for the sake of creating a framework, as opposed to > those written to meet a defined need, tend to be the worst examples of > masturbatory coding. Indeed, but masturbation is perfectly healthy and acceptable, and we all do it every now and then. It is however, much like the framework in question, best kept private and not made public. Ed -- http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
rogerdpack wrote: on this page http://docs.python.org/3.1/tutorial/introduction.html some of the "text" examples are [incorrectly] color formatted. I did not see any problems with my browser (FF3.5), so please be more specific. I assume this a bug reportable to bugs.python.org? Yes, this would be a components: documentation issue. Since you are new to this, reporting and asking here first is a good idea. (The tracker already has too many invalid newbie reports.) tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
JonathanB writes: > Any other tips? Learn some more languages besides Python. Python is good to know but other languages present other ways of doing things. A skillful programmer has a variety of techniques to draw from. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 6:15 pm, Thomas Philips wrote: > I mis-spoke - the variance is infinite when df=2 (the variance is df/ > (df-2), Yes: the variance is infinite both for df=2 and df=1, and Student's t with df=1 doesn't even have an expectation. I don't see why this would stop you from generating meaningful samples, though. > and you get the Cauchy when df=2. Are you sure about this? All my statistics books are currently hiding in my mother-in-law's attic, several hundred miles away, but wikipedia and mathworld seem to say that df=1 gives you the Cauchy distribution. > I made the mistake because the denominator is equivalent to the > square root of the sample variance of df normal observations, As I'm reading it, the denominator is the square root of the sample variance of *df+1* independent standard normal observations. I agree that the wikipedia description is a bit confusing. It seems that there are uses for Student's t distribution with non-integral degrees of freedom. The Boost library, and the R programming language both allow non-integral degrees of freedom. So (as Robert Kern already suggested), you could drop the test for integrality of df. In fact, you could just drop the tests on df entirely: df <= 0.0 will be picked up in the gammavariate call. -- Mark -- http://mail.python.org/mailman/listinfo/python-list
pickle error - 'module' object has no attribute '_reconstruct'
Saw a new-to-me error today when trying to unpickle a moderately large object (about 500k): AttributeError: 'module' object has no attribute '_reconstruct' Google turned up nothing as far as I could tell, "_reconstruct" doesn't appear in the docs and pickletools.dis() was happy to disassemble the pickle. This was with Python 2.4. Any ideas about the cause of this error? Thx, Skip Montanaro -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle error - 'module' object has no attribute '_reconstruct'
Skip Montanaro pobox.com> writes: > > Saw a new-to-me error today when trying to unpickle a moderately large > object (about 500k): > > AttributeError: 'module' object has no attribute '_reconstruct' I believe I have it figured out. Most of the pickled data consists of numpy arrays. It appears I picked up an ancient version of numpy when I got the failure. S -- http://mail.python.org/mailman/listinfo/python-list
Re: evolution [was Re: An assessment of the Unicode standard]
r wrote: I'd like to present a bug report to evolution, obviously the garbage collector is malfunctioning. I think most people think that when they read the drivel that you generate. I'm done with your threads and posts. *plonk* -- http://mail.python.org/mailman/listinfo/python-list
IMGCrush (New Python image optimizing tool)
Hello people, I started to work on a small Python script to simplify mass conversion of images for a website I was working on. I eventually got interested in the script more than the site istelf, and it got a lot bigger, so I released it as an opensource project It's licensed under BSD and not very polished yet, but I think I reached a point where it's at least partially usable. It should run on most Unixes but it's not compatible with Windows (using unix shell). IMGCrush (as it's called) tries to save given image (or images, it can process directories of images as well) with the smallest possible filesize, so it works similarly to pngcrush and other png optimizers, with the exception that it can also save to GIF, JPG, PNG, and user can specify image quality loss he/she can tolerate. The way it's used is that the user for instance specfies that he/she wants an image with smallest possible size with at least 99% quality or the highest quality image with 50% of size of input, etc. (there are also other ways to measure quality/size). Quality isn't measured in a very "human" way now, which will hopefully change in future. IMGCrush is also quite slow at the moment, and will probably never be fast, but it can be a lot faster than it is now. Project is hosted at Launchpad: Homepage link: https://launchpad.net/icrush Downloads: https://launchpad.net/icrush/+download Use at your own risk :-) run "imgcrush --help" for usage instructions. Criticism/ideas/whatever is welcome. -Kiith-Sa -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
Il Wed, 02 Sep 2009 10:22:50 +0100, MRAB ha scritto: > The preferred option these days is to slow down net access of the > offenders, not cut them off completely. I'm not sure how many ISPs > actually do that yet. If they do, it doesn't look like it's working that much. D. -- http://mail.python.org/mailman/listinfo/python-list
Re: Entry Level Python Jobs
On Sep 2, 12:52 pm, JonathanB wrote: > Any other tips? I'm probably going to come off as very old school, but give yourself a good and thorough education in data structures and algorithms. You might never be called on to actually code a quick sort, merge sort, heap sort, doubly-linked list or trie, but knowing what they are and why they are important will fundamentally shape how you approach all software problem solving. There are a lot of good data structures and algorithms books that use C, so that'd be a good approach to also adding a very important language to your toolbelt. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 6:51 am, Thomas Philips wrote: > While the random module allows one to generate randome numbers with a > variety of distributions, some useful distributions are omitted - the > Student's t being among them. I'm curious to hear what your use cases are. My understanding is that t-distribution is an estimation tool used with small samples of a population where the variance or standard deviation is unknown. So, when do you ever need to generate random variables with this distribution? ISTM that this is akin to wanting a generator for a Kolmogorov distribution -- usually the distribution is used to test empirical data, not to generate it. I think most of the existing generators were chosen because they are useful in simulation programs. AFAICT, the Student's t- distribution doesn't fall into that category (usually, you know the population standard deviation when you're the one generating data). ISTM, there ought to be a statistics module that can calculate cumulative distribution functions for a variety of distributions. This would be far more helpful than creating more generators. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
Steven D'Aprano wrote: On Wed, 02 Sep 2009 02:16:27 -0400, Terry Reedy wrote: The rationale I have seen is this: if one leaves the wi-fi router open and illegal activity is conducted thru it, and there is no residual evidence on the hard drives of on-premises machines, then one may claim that it must have been someone else. On the other hand, if the router is properly closed, then it will be hard to argue that someone hacked trough it. There are, of course, flaws in this argument, and I take it as evidence of intention to conduct illegal activity, whether properly so or not. So, if somebody leaves their car unlocked, is that evidence that they were intending to rob a bank and wanted a fast getaway car? If you leave your window open on a hot summer's night, is that evidence that you're planning to fake a burglary? If you leave your knife and fork unattended in a restaurant while you go to the toilet, is that evidence that you intended to stab the waiter and blame somebody else? I assume you would answer No to each of these. So why the harsher standard when it comes to computer crime? Your cases are not at all analogous or parallel. First, I did not say 'computer crime'. I said 'illegal activity, whether properly so [illegal] or not'. The latter is much broader, sometimes including the viewing of non-sexual pictures of undraped young adults. Second, I was talking about advocacy of 'open windows' by someone who knows how to close and lock a window. So the analogy would be someone who advocates leaving your living room window open so that if the Feds come knocking on your door about 'illegal' materials being sent to or from your home, you can claim that the within-house sender or receiver must have been a stranger that came in through the window. H. [Of course, with unlockable street-side mailboxes, a stranger would not need an open window to do such.] Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
> To get this into core Python, you'd usually submit a feature request > athttp://bugs.python.org. If you do submit a patch, please assign it to me. I've been the primary maintainer for that module for several years. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On Sep 2, 12:33 pm, Steven D'Aprano wrote: (snip) > I learned one thing though. System Restore sounds like a good idea, but > in my experience it's only good for restoring malware when you reboot. System restore is a joke! and a complete waste of HD space even if you have TB's to spare! Actually i can do with almost very piece of built- in software on this stinking windows platform. Microsoft's whole system of security is a joke as evidenced by Stevens experience. Windows ships with back doors wide open just begging for an infection! - BS Packaged software - Windows Mail -> virus magnet/backdoor use gmail Internet Exploder -> virus magnet/frontdoor, use Chrome|Mozilla Windows Calendar -> only slightly useful Windows Media Player -> complete bloatware Windows Media Center -> bloatware built on bloatware Windows sync center -> what a joke! Windows Movie Maker -> yea for kids and housewife's! Windows Photo Galley -> only slightly useful. Windows Update -> well i don't like hosting viruses so...? My meeting place -> worthless junk Windows Games -> *puke* *Dangerous and annoying services and settings from the factory* -Remote Resitry -> completly moronic! -Remote assistance -hide known filetypes -> Donde es "destroy useless bloatware button" -UAC -> what a nagging POS! -Menus are hidden by default in explorer -Ready Boost -> *puke* -Internet Connection Sharing -NET Tcp port sharing -Secondary Logon -Terminal Services -Windows BackUp -Windows remote managment -Routing and Remote Access -All Peer * services -all Windows Media center/player network services -- Accessories crap! -- Calculator -> POS, use the python shell instead CMD -> What else ya gonna use? Notepad -> What a useless POS, only one undo! COME ON! Paint -> are you jokeing M$ -- Glorified etch-a-sketch! sidebar -> Yes i love wasting memory just to see an analog clock! sound recorder -> very slightly useful, needs more functionality WordPad -> no thanks, OO will suffice! charactor map -> only slightly useful defragmenter -> too slow disk cleanup -> obviously made for morons! Internet Explorer(no add-ons) -> polish a turd, still a turd! Windows Experience index -> useless bloat Computer Management -> horrible UI Task Manager -> The worst UI i have ever used! (Vista) Windows Help -> maybe for complete morons! --- misc bloat --- Desktop backgrounds -> crap! use a solid color (black is my fav!) Sceen savers -> crap! ohh...look at the pretty colors! Windows Transparency -> crap! vanity run muck! Themes -> crap! adolescent accessorizing! Sadly none of these built in memory robbing hard space eating annoying POS bloatwares can be uninstalled. The only advancement (if you could call it that) with Vista is the search from start menu is much better than the previous "puppy dog" search of XP. Short of that Vista is just lipstick on a pig! Thanks M$ for bending us over yet again! -- http://mail.python.org/mailman/listinfo/python-list
notes
Requires ImageMagick and Python (coded in python 2.x, I'm running 2.6 but it might run on older python as well) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On Sep 2, 4:22 am, MRAB wrote: > The preferred option these days is to slow down net access of the > offenders, not cut them off completely. I'm not sure how many ISPs > actually do that yet. That seems to be the case with ISP and "good" users also in the form of quotas ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: notes
On Sep 2, 9:27 pm, "[email protected]" wrote: > Requires ImageMagick and Python (coded in python 2.x, I'm running 2.6 > but it might run on older python as well) Sorry, got confused by Google Groups interface and posted a new topic instead of just replying -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On 9/2/2009 7:07 AM Unknown said... A spam/malware merchange who can't afford/arrange other internet access? How is net access on the critical path? Mailbots (a significant source of spam IMHO) thrive on net access -- for them, is there anything _more_ critical? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: IMGCrush (New Python image optimizing tool)
On Sep 2, 8:59 pm, "[email protected]" wrote: > Hello people, > > I started to work on a small Python script to simplify mass conversion > of images for a website I was working on. > I eventually got interested in the script more than the site istelf, > and it got a lot bigger, so I released it as an opensource project > > It's licensed under BSD and not very polished yet, but I think I > reached a point where it's at least partially usable. > It should run on most Unixes but it's not compatible with Windows > (using unix shell). > > IMGCrush (as it's called) tries to save given image (or images, it can > process directories of images as well) > with the smallest possible filesize, so it works similarly to pngcrush > and other png optimizers, with the exception that it can also save to > GIF, JPG, PNG, and user can specify image quality loss he/she can > tolerate. > > The way it's used is that the user for instance specfies that he/she > wants an image with smallest possible size with at least 99% quality > or the highest quality image with 50% of size of input, etc. (there > are also other ways to measure quality/size). > Quality isn't measured in a very "human" way now, which will hopefully > change in future. > IMGCrush is also quite slow at the moment, and will probably never be > fast, but it can be a lot faster than it is now. > > Project is hosted at Launchpad: > Homepage link:https://launchpad.net/icrush > Downloads: https://launchpad.net/icrush/+download > > Use at your own risk :-) > run "imgcrush --help" for usage instructions. > > Criticism/ideas/whatever is welcome. > > -Kiith-Sa Requires ImageMagick and Python (coded in python 2.x, I'm running 2.6 but it might run on older python as well) -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On Sep 2, 2:37 pm, Mark Dickinson wrote: > On Sep 2, 6:15 pm, Thomas Philips wrote: > > > I mis-spoke - the variance is infinite when df=2 (the variance is df/ > > (df-2), > > Yes: the variance is infinite both for df=2 and df=1, and Student's t > with df=1 doesn't even have an expectation. I don't see why this > would stop you from generating meaningful samples, though. > > > and you get the Cauchy when df=2. > > Are you sure about this? All my statistics books are currently hiding > in my mother-in-law's attic, several hundred miles away, but wikipedia > and mathworld seem to say that df=1 gives you the Cauchy distribution. > > > I made the mistake because the denominator is equivalent to the > > square root of the sample variance of df normal observations, > > As I'm reading it, the denominator is the square root of the sample > variance of *df+1* independent standard normal observations. I agree > that the wikipedia description is a bit confusing. > > It seems that there are uses for Student's t distribution with > non-integral degrees of freedom. The Boost library, and the R > programming language both allow non-integral degrees of freedom. > So (as Robert Kern already suggested), you could drop the test > for integrality of df. In fact, you could just drop the tests > on df entirely: df <= 0.0 will be picked up in the gammavariate > call. > > -- > Mark To tell you the truth, I have never used it with a non-integer number of degrees of freedom, but that's not the same as saying that df should be an integer. When df is an integer, one can interpret the t- distribution as the ratio of a unit normal (i.e. N(0,1)) to the sample standard deviation of a set of df+1 unit normals divided by sqrt(df +1). However, as Robert Kern correctly observes, the distribution is defined for all positive non-integer df, though we then lose the above interpretation, and must think of it in abstract terms. The distribution has infinite variance when df=2 and an undefined mean when df<=1, but the code can still be used to generate samples. Whether or not these samples make sense is altogether another question, but it's easy enough to remmove the restrictions. -- http://mail.python.org/mailman/listinfo/python-list
Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)
> I dont know guppy, > but if h.load(f) raises StopIteration upon eof, as seems implied by your > proposal, then something like the following would work. > > sets.extend(h.load(f) for _ in xrange(1e9)) Sounds like hpy has a weird API. Either it should be an iterator supporting __iter__() and next() and raising StopIteration when it's done, or it should simply return None to indicate an empty load. In the first case, you would write: sets.extend(h.load(f)) And in the second case: sets.extend(iter(partial(h.load, f), None)) The first way just uses the iterator protocol in a way that is consistent with the rest of the language. The second way, using the two argument form of iter(), is the standard way of creating an iterator from a function that has a sentinel return value. IOW, it is not normal to use StopIteration in a function that isn't an iterator. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
On 2009-09-02, Emile van Sebille wrote: > On 9/2/2009 7:07 AM Unknown said... >> A spam/malware merchange who can't afford/arrange other >> internet access? How is net access on the critical path? > > Mailbots (a significant source of spam IMHO) thrive on net access -- for > them, is there anything _more_ critical? A mailbot which would otherwise not have network access is going to come park itself outside my house if I leave my AP open? There are open APs at all sorts of libraries, coffee houses, restaurants, auto dealers, book stores, etc, etc. I don't see how net access is an issue for somebody who wants to send spam. -- Grant Edwards grante Yow! Now I am depressed ... at visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
Il 02 Sep 2009 00:17:05 GMT, Steven D'Aprano ha scritto: > This can be done already, without the need for an email tax. ISPs could > easily detect spammers, if they cared to. > > There are a few things that can already be done to cut the spam problem > to manageable size: > > (1) Why aren't ISPs blocking port 25 for home users by default? My home >[...] > (2) Why aren't ISPs cutting off detected spam bots? Owners of zombied PCs [...] > (3) ISPs who won't cut off spam bots are either incompetent or have a > financial incentive to do business with spammers. Therefore, responsible > ISPs should cut them off. If this means the email universe divides into > two halves, the Wild West where 999 emails out of every 1000 are spam, > and Civilization where only one in a thousand is spam, I'm okay with that. I don't know ISP's internal dynamics so I can't imagine what kind of financial incentive they have with spammers, AFAIK ISPs must sustain costs to augment their infrastructures to face this huge amount of traffic, costs charged on the subscribers monthly bill. At first this conduct can appear convenient but higer fares lead to reduced competitivity on the market. There are opposing forces that I can not interpret, so can not give an answer for that. > > As for the argument that home users who send spam are the victim, that's > true up to a point, but not very far. Here's an analogy: suppose that > terrorists sneak into your house after picking the lock -- or in the case > of Windows users with no firewall or anti-malware, stroll through the > unlocked front door -- and spend the next six months camped in your spare > bedroom, using your home for their base of operations while they make > terrorist attacks. When the FBI kicks your doors down, don't you think > you would be arrested and would have to prove that you couldn't be > reasonably expected to know they were there? If millions of spam emails > are coming out of your PC, that's prima facie evidence that YOU are > spamming. You would need to prove that you're an innocent victim who > couldn't *reasonably* be expected to know that your machine was hijacked > -- you would need to prove that the spam bot was so sophisticated that it > infected your PC despite the firewall, that you didn't install it > yourself in order to get some stupid game, that no commonly available > anti-malware program detects it. Anything less than that is *at least* > negligence, and possibly willful negligence. Mmh, sounds like a presumption of guilt. I wouldn't go so far on this way. The metaphor of terrorists in the bedroom applies up to a point. While it's evident that you can not be unaware of people living in your home, modern malware is made to be silent to the infected computer, so it's a hidden menace and not so evident. You are depicting a situation where the owner is perfectly aware of whats happening on his machine, but this is not always the case. I agree that ignorance is not an excuse but I wouldn't use the harsh manners at first. I think that the owner of the infected computer should be warned by his ISP, who can easily monitor the amount of traffic, and being induced to take countermisures. If that warning is an amount of maney to pay proportional to mail generated, I'm confident that it would be 'inducing' enough. After that the situation can develop only in three possible ways: 1) the owner takes appropriate countermisures proving his innocence (but he must pay the mail-tax for the period of infection!) 2) the owner takes no countermisures and pays the tax: it's very likely he is a spammer and we can start the assault with tanks 3) the owner takes no countermisures and doesn't pay the tax: well, It's up to you to choose the action to take towards him. [...] > Yes, I'd like to see the criminals, the malware authors and the spammers > punished, but I'd be satisfied to see them put out of business. The weak > link is the zombie PCs -- fix the home users' PCs, or block them, take > them off the Internet, and spam becomes manageable again. you got the crux of the matter. regards David -- http://mail.python.org/mailman/listinfo/python-list
Re: exec globals and locals
On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin wrote:
> Hi,
> Being fairly new to Python, I'm trying to figure out the best way to use the
> exec statement and I must admit that I am a bit lost.
>
> Consider this case:
> exec "print 'a'" in {},{} [exp.1]
> It means that I'm (kindly) asking the interpreter to execute the code
> string "print 'a'" with empty globals and locals.
> Considering that globals and locals are empty, I would expect [exp.1] to
> raise an exception about 'print' not being known.
In Python versions prior to 3.0, print is a statement (like for,
while, if, etc), not a function (note how you don't need parentheses
when using it); so it doesn't matter whether the built-in functions
are available or not, print will still work.
Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: exec globals and locals
2009/9/2 Chris Rebert
> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin
> wrote:
> > Hi,
> > Being fairly new to Python, I'm trying to figure out the best way to use
> the
> > exec statement and I must admit that I am a bit lost.
> >
> > Consider this case:
> > exec "print 'a'" in {},{} [exp.1]
> > It means that I'm (kindly) asking the interpreter to execute the code
> > string "print 'a'" with empty globals and locals.
> > Considering that globals and locals are empty, I would expect [exp.1] to
> > raise an exception about 'print' not being known.
>
> In Python versions prior to 3.0, print is a statement (like for,
> while, if, etc), not a function (note how you don't need parentheses
> when using it); so it doesn't matter whether the built-in functions
> are available or not, print will still work.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
Ok, thanks for the explanation.I'm really confused with print being a
statement but it's seems that I won't have to put too much effort on
understanding why since 3.0 states the contrary. :p
By the way, could you suggest me a link that explains why 3.0 changed this.
It might provide some material to understand the pros and cons of "function
statements".
Regards,
Quentin
--
http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
In article , rogerdpack wrote: > >on this page > >http://docs.python.org/3.1/tutorial/introduction.html > >some of the "text" examples are [incorrectly] color formatted. > >I assume this a bug reportable to bugs.python.org? Actually, for doc bugs you should follow the instructions in the docs, see the link "Reporting bugs" at e.g. http://docs.python.org/3.1/ -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet -- http://mail.python.org/mailman/listinfo/python-list
Re: exec globals and locals
On Wed, Sep 2, 2009 at 1:13 PM, Quentin Lampin wrote:
> 2009/9/2 Chris Rebert
>>
>> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin
>> wrote:
>> > Hi,
>> > Being fairly new to Python, I'm trying to figure out the best way to use
>> > the
>> > exec statement and I must admit that I am a bit lost.
>> >
>> > Consider this case:
>> > exec "print 'a'" in {},{} [exp.1]
>> > It means that I'm (kindly) asking the interpreter to execute the code
>> > string "print 'a'" with empty globals and locals.
>> > Considering that globals and locals are empty, I would expect [exp.1] to
>> > raise an exception about 'print' not being known.
>>
>> In Python versions prior to 3.0, print is a statement (like for,
>> while, if, etc), not a function (note how you don't need parentheses
>> when using it); so it doesn't matter whether the built-in functions
>> are available or not, print will still work.
>>
>> Cheers,
>> Chris
>> --
>> http://blog.rebertia.com
>
> Ok, thanks for the explanation.
> I'm really confused with print being a statement but it's seems that I won't
> have to put too much effort on understanding why since 3.0 states the
> contrary. :p
> By the way, could you suggest me a link that explains why 3.0 changed this.
> It might provide some material to understand the pros and cons of "function
> statements".
http://www.python.org/dev/peps/pep-3105/ (PEP 3105 -- Make print a function)
http://mail.python.org/pipermail/python-dev/2005-September/056154.html
Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: exec globals and locals
2009/9/2 Chris Rebert
> On Wed, Sep 2, 2009 at 1:13 PM, Quentin Lampin
> wrote:
> > 2009/9/2 Chris Rebert
> >>
> >> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin >
> >> wrote:
> >> > Hi,
> >> > Being fairly new to Python, I'm trying to figure out the best way to
> use
> >> > the
> >> > exec statement and I must admit that I am a bit lost.
> >> >
> >> > Consider this case:
> >> > exec "print 'a'" in {},{} [exp.1]
> >> > It means that I'm (kindly) asking the interpreter to execute the code
> >> > string "print 'a'" with empty globals and locals.
> >> > Considering that globals and locals are empty, I would expect [exp.1]
> to
> >> > raise an exception about 'print' not being known.
> >>
> >> In Python versions prior to 3.0, print is a statement (like for,
> >> while, if, etc), not a function (note how you don't need parentheses
> >> when using it); so it doesn't matter whether the built-in functions
> >> are available or not, print will still work.
> >>
> >> Cheers,
> >> Chris
> >> --
> >> http://blog.rebertia.com
> >
> > Ok, thanks for the explanation.
> > I'm really confused with print being a statement but it's seems that I
> won't
> > have to put too much effort on understanding why since 3.0 states the
> > contrary. :p
> > By the way, could you suggest me a link that explains why 3.0 changed
> this.
> > It might provide some material to understand the pros and cons of
> "function
> > statements".
>
> http://www.python.org/dev/peps/pep-3105/ (PEP 3105 -- Make print a
> function)
> http://mail.python.org/pipermail/python-dev/2005-September/056154.html
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
Thanks a lot Chris!
Quentin
--
http://mail.python.org/mailman/listinfo/python-list
Re: Simple addition to random module - Student's t
On 2009-09-02 14:15 PM, Raymond Hettinger wrote: On Sep 2, 6:51 am, Thomas Philips wrote: While the random module allows one to generate randome numbers with a variety of distributions, some useful distributions are omitted - the Student's t being among them. I'm curious to hear what your use cases are. My understanding is that t-distribution is an estimation tool used with small samples of a population where the variance or standard deviation is unknown. So, when do you ever need to generate random variables with this distribution? ISTM that this is akin to wanting a generator for a Kolmogorov distribution -- usually the distribution is used to test empirical data, not to generate it. In more complicated models, estimates of one parameter need to be propagated through the model, particularly if you are looking at sensitivity to parameters. Student's t describes the variation of an estimate of a mean of a sample from a Gaussian distribution. If I were modeling a processing wherein someone makes an estimate of a mean and then acts on that estimate, I would want to generate random t variates to feed that model. I think most of the existing generators were chosen because they are useful in simulation programs. AFAICT, the Student's t- distribution doesn't fall into that category (usually, you know the population standard deviation when you're the one generating data). Student's t distribution is also used as a sort of generic fat-tailed distribution in some models and is not tied to the "estimate of a mean" description. ISTM, there ought to be a statistics module that can calculate cumulative distribution functions for a variety of distributions. This would be far more helpful than creating more generators. Yes, scipy.stats. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
On Sep 2, 12:30 pm, Terry Reedy wrote: > rogerdpack wrote: > > on this page > > >http://docs.python.org/3.1/tutorial/introduction.html > > > some of the "text" examples are [incorrectly] color formatted. > > I did not see any problems with my browser (FF3.5), so please be more > specific. search for "This is a rather long string containing" I suppose this is more of a documentation bug... -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem w/ mysqldump
I tried running it like you said, got this error: 'mysqldump' is not a recognized internal or external command. If I could just figure out in what file the data were stored, I could copy it and try it in another computer. Any ideas? TIA, V On Wed, Sep 2, 2009 at 2:10 PM, Rami Chowdhury wrote: > I tried running the mysqldump command >> from the python prompt >> > > I think you were being asked to try running it from the command prompt > (cmd.exe) -- it won't work from the Python prompt, of course. > > > On Wed, 02 Sep 2009 10:50:55 -0700, Victor Subervi < > [email protected]> wrote: > > I am running this on Windoze. I do not use the mysql db without python. I'm >> just building something for a client. I tried running the mysqldump >> command >> from the python prompt. Didn't know I could do that :) It tells me >> "mysqldump is not defined" :( >> V >> >> On Wed, Sep 2, 2009 at 11:48 AM, Nitebirdz > >wrote: >> >> On Wed, Sep 02, 2009 at 08:43:22AM -0400, Victor Subervi wrote: >>> > >>> > Obviously I'm sure. It created the file. But the file was blank. How >>> can >>> I >>> > do a mysqldump in mysql itself? >>> > >>> >>> As I said, I only got a blank file when the actual command itself >>> failed. How do you dump the MySQL database itself without using Python? >>> Just run the 'mysqldump' command from the prompt. Is that what you are >>> asking? >>> >>> Are you running this on Windows? What OS? You do have the 'mysqldump' >>> command available from the shell prompt and in your path, right? >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -- http://mail.python.org/mailman/listinfo/python-list
Re: pickling question
Many thanks for the responses I've received here to my question (below).
After reading the responses, I understand what the problem is much better. In
addition to the solutions mentioned in the responses, now that I understand the
problem I'll offer up my own solution. The following is an executable script
named pick1.py:
===
import pickle
class A(object):
def __init__(self, x):
self.x = x
def writePickle():
import pick1
a5 = pick1.A(5)
f = open('pick1.pickle', 'wb')
pickle.dump(a5, f)
f.close()
writePickle() # The dumped pickle can be read by any other script.
That is, we need to do the pickling in a context where the module name for the
class is "pick1" rather than "__main__". The example above allows us to do that
without changing __name__ or doing anything else of that nature.
Thanks again!
Gary
> When you define a class in a script, and then pickle instances of
> that class in the same script and store them to disk, you can't load
> that pickle in another script. At least not the straightforward way
> [pickle.load(file('somefile.pickle'))]. If you try it, you get an
> AttributeError during the unpickling operation.
>
> There is no problem, of course, if the class is defined in a module
> which is imported by the pickling script.
> pickle.load(file('somefile.pickle')) then works.
>
> Rather than provide specific examples here, there's a blog post from
> 2005 that discusses this issue in depth and presents the problem very
> well: http://stefaanlippens.net/pickleproblem. (I tested in Python
> 2.6 yesterday and the same issue persists.)
>
> Questions:
>
> 1) Does this have to be the case, or is it a design problem with
> pickles that should be remedied?
>
> 2) Is there an easier way around it than moving the class definition
> to a separate module? The blog post I point to above suggests putting
> "__module__ = os.path.splitext(os.path.basename(__file__))[0]" into
> the class definiton, but that's not working in my testing because
> when I do that, the pickling operation fails. Is there something else
> that can be done?
>
> This is obviously not a huge problem. Substantial classes should
> usually be defined in a separate module anyway. But sometimes it
> makes sense for a script to define a really simple, small class to
> hold some data, and needing to create a separate module just to
> contain such a class can be a little annoying.
--
Gary Robinson
CTO
Emergent Music, LLC
personal email: [email protected]
work email: [email protected]
Company: http://www.flyfi.com
Blog:http://www.garyrobinson.net
--
http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
rogerdpack schrieb: On Sep 2, 12:30 pm, Terry Reedy wrote: rogerdpack wrote: on this page http://docs.python.org/3.1/tutorial/introduction.html some of the "text" examples are [incorrectly] color formatted. I did not see any problems with my browser (FF3.5), so please be more specific. search for "This is a rather long string containing" I suppose this is more of a documentation bug... I don't see any wrong formatting. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
Diez B. Roggisch wrote: rogerdpack schrieb: On Sep 2, 12:30 pm, Terry Reedy wrote: rogerdpack wrote: on this page http://docs.python.org/3.1/tutorial/introduction.html some of the "text" examples are [incorrectly] color formatted. I did not see any problems with my browser (FF3.5), so please be more specific. search for "This is a rather long string containing" I suppose this is more of a documentation bug... I don't see any wrong formatting. I see what the OP means. The blocks with a green background mostly contain code with syntax colouring, but a couple of them show what's printed when the code is run, _also_ with syntax colouring. I've copied the text below, indicating the coloured words with underscores: This _is_ a rather long string containing several lines of text just _as_ you would do _in_ C. Note that whitespace at the beginning of the line _is_ significant. -- http://mail.python.org/mailman/listinfo/python-list
Re: website feedback to where?
MRAB schrieb: Diez B. Roggisch wrote: rogerdpack schrieb: On Sep 2, 12:30 pm, Terry Reedy wrote: rogerdpack wrote: on this page http://docs.python.org/3.1/tutorial/introduction.html some of the "text" examples are [incorrectly] color formatted. I did not see any problems with my browser (FF3.5), so please be more specific. search for "This is a rather long string containing" I suppose this is more of a documentation bug... I don't see any wrong formatting. I see what the OP means. The blocks with a green background mostly contain code with syntax colouring, but a couple of them show what's printed when the code is run, _also_ with syntax colouring. I've copied the text below, indicating the coloured words with underscores: This _is_ a rather long string containing several lines of text just _as_ you would do _in_ C. Note that whitespace at the beginning of the line _is_ significant. Ah. Now I see - but *barely*, which might be a question of text-rendering and browser-defaults. Diez -- http://mail.python.org/mailman/listinfo/python-list
Creating slice notation from string
I'm trying to NOT create a parser to do this and I'm sure that it's easy if I could only see the light! Is it possible to take an arbitrary string in the form "1:2", "1", ":-1", etc. and feed it to slice() and then apply the result to an existing list? For example, I have a normal python list. Let's say that x = [1,2,3,4] and I have a string, call it "s', in the format "[2:3]". All I need to do is to apply "s" to "x" just like python would do. I can, of course, convert "x" to a list with split(), convert the 2 and 3 to ints, and then do something like: x[a:b] ... but I'd like something more general. I think the answer is in slice() but I'm lost. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating slice notation from string
bvdp wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form "1:2", "1",
":-1", etc. and feed it to slice() and then apply the result to an
existing list?
For example, I have a normal python list. Let's say that x = [1,2,3,4]
and I have a string, call it "s', in the format "[2:3]". All I need to
do is to apply "s" to "x" just like python would do.
I can, of course, convert "x" to a list with split(), convert the 2
and 3 to ints, and then do something like: x[a:b] ... but I'd like
something more general. I think the answer is in slice() but I'm lost.
>>> x = [1,2,3,4]
>>> s = "[2:3]"
>>> # Using map.
>>> x[slice(*map(int, s.strip("[]").split(":")))]
[3]
>>> # Using a list comprehension.
>>> x[slice(*[int(i) for i in s.strip("[]").split(":")])]
[3]
--
http://mail.python.org/mailman/listinfo/python-list
Re: Creating slice notation from string
On 2009-09-02 16:55 PM, bvdp wrote:
I'm trying to NOT create a parser to do this and I'm sure that
it's easy if I could only see the light!
Is it possible to take an arbitrary string in the form "1:2", "1",
":-1", etc. and feed it to slice() and then apply the result to an
existing list?
For example, I have a normal python list. Let's say that x = [1,2,3,4]
and I have a string, call it "s', in the format "[2:3]". All I need to
do is to apply "s" to "x" just like python would do.
I can, of course, convert "x" to a list with split(), convert the 2
and 3 to ints, and then do something like: x[a:b] ... but I'd like
something more general. I think the answer is in slice() but I'm lost.
For a one-liner:
x[slice(*map(int, x[1:-1].split(':')))]
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list
