Where does MySQLdb put inserted data?
Hi,
As of late clipboard pasting into a terminal sometimes fails (a
known bug, apparently), I use MySQLdb to access MySQL tables. In general
this works just fine. But now I fail filling a new table. The table
exists. "mysql>EXPLAIN new_table;" explains and "root@blackbox-one:/#
sudo/find / -name 'new_table*'" finds "/var/lib/mysql/fr/new_table.frm".
So I do "cursor.executemany ('insert into new_table values (%s)' %
format, data)". No error occurs and "cursor.execute ('select * from
new_table;')" returns the number of records read, and "cursor.fetchall
()" returns all new records. All looks fine, but "mysql>SELECT * FROM
new_table;" produces an "Empty set" and "sudo find / -name 'new_table*"
still finds only the format file, same as before.
Could it have to do with COMMIT. I believe I am using ISAM tables
(default?) and those don't recognize undo commands, right?. Anyway, an
experimental "cursor.execute ('COMMIT')" didn't make a difference. It
looks like MySQLdb puts the data into a cache and that cache should be
saved either by the OS or by me. Strange thing is that this is one freak
incident in an almost daily routine going back years and involving
thousands of access operations in and out acting instantaneously. I seem
to remember a similar case some time ago and it also involved a new
empty table.
Thanks for hints
Frederic
mysql> select version()
-> ;
+-+
| version() |
+-+
| 5.5.31-0ubuntu0.12.04.1 |
+-+
1 row in set (0.00 sec)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Multiple scripts versus single multi-threaded script
Roy Smith wrote: > Threads are lighter-weight. That means it's faster to start a new > thread (compared to starting a new process), and a thread consumes fewer > system resources than a process. If you have lots of short-lived tasks > to run, this can be significant. If each task will run for a long time > and do a lot of computation, the cost of startup becomes less of an > issue because it's amortized over the longer run time. This might be true on Windows, but I think on Linux process overheads are pretty similar to threads, e.g. http://stackoverflow.com/questions/807506/threads-vs-processes-in-linux Combined with the lack of a GIL-conflict, processes can be pretty efficient. Jeremy -- https://mail.python.org/mailman/listinfo/python-list
Re: wil anyone ressurect medusa and pypersist?
On Thursday, 3 October 2013 21:48:35 UTC+1, [email protected] wrote: > On Thursday, May 16, 2013 11:15:45 AM UTC-7, [email protected] wrote: > > > www.prevayler.org in python = pypersist > > > > > > > > > > > > medusa = python epoll web server and ftp server eventy and async > > > > wow interesting > > > > sprevayler ?? > > > > cl-prevalence Hmm - FWIW this looks a lot like it's from 'gavino', a troll-like entity on c.l.forth. J^n -- https://mail.python.org/mailman/listinfo/python-list
Re: Where does MySQLdb put inserted data?
On Fri, 04 Oct 2013 09:38:41 +0200, F.R. wrote: > Hi, > As of late clipboard pasting into a terminal sometimes fails (a > known bug, apparently), I use MySQLdb to access MySQL tables. [...] You appear to have posted to the wrong list. This is a Python list, not MySQL. Nothing in your question appears to be about Python. If I am mistaken, please re-word your question explain what Python code you are having trouble with, what you tried, what you expected, and what it actually did. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Thursday, October 3, 2013 5:33:27 AM UTC+8, Terry Reedy wrote: > On 10/2/2013 8:31 AM, [email protected] wrote: > > > On Tue, Oct 1, 2013, at 17:30, Terry Reedy wrote: > > >> Part of the reason that Python does not do tail call optimization is > > >> that turning tail recursion into while iteration is almost trivial, once > > >> you know the secret of the two easy steps. Here it is. > > > > > > That should be a reason it _does_ do it - saying people should rewrite > > > their functions with loops means declaring that Python is not really a > > > multi-paradigm programming language but rather rejects functional > > > programming styles in favor of imperative ones. > > > > It is true that Python does not encourage the particular functional > > style that is encouraged by auto optimization of tail recursion. A > > different functional style would often use reduce (or fold) instead. > > > > Some other points I left out in a post of medium length yet brief for > > the topic. > > > > 1. If one starts with body recursion, as is typical, one must consider > > commutativity (possibly associativity) of the 'inner' operator in any > > conversion. > > > > 2. Instead of converting to tail recursion, one might convert to while > > iteration directly. > > > > 3. One often 'polishes' the while form in a way that cannot be done > > automatically. > > > > 4. While loops are actually rare in idiomatic Python code. In Python, > > for loops are the standard way to linearly process a collection. The > > final version I gave for a factorial while loop, > > > > def fact_while(n): > >if n < 0 or n != int(n): > > raise ValueError('fact input {} is not a count'.format(n)) > >fac = 1 > >while n > 1: > > fac *= n > > n -= 1 > >return fac > > > > should better be written with a for loop: > As I pointed out before, an accelerated version without the limit of the stack depth for computing facotrials can be obtained by storing a list of products of primes first. Of course integer divisions are required to transform the to stack depth problem into the size of the 32-64 bit heap space. -- https://mail.python.org/mailman/listinfo/python-list
howto check programs and C libraries
Hello, I'm in charge of preparing a computer room for the practices of "introduction to programming". One of the tasks is checking that from all the computers in the room one can execute some programs and link (and compile) against some libraries. My first idea was using Autotools (or cmake), but as I'm a big fan of python, I was thinking how to do that with python, and I don't have a clear solution yet. I know that distutils includes the distutils.command.config module, and I think it could do the job (when properly subclassed). Do you have a better idea? Thanks in advance. Regards, DPalao -- https://mail.python.org/mailman/listinfo/python-list
Re: ipy %run noob confusion
On 3 October 2013 18:42, wrote: > I have some rather complex code that works perfectly well if I paste it in by > hand to ipython, but if I use %run it can't find some of the libraries, but > others it can. The confusion seems to have to do with mathplotlib. I get it > in stream by: > >%pylab osx > > and do a bunch of stuff interactively that works just fine, for example: > > clf() > > But I want it to run on a %run, but %pylab is (apparently) not allowed from a > %run script, and importing matplotlib explicitly doesn't work...I mean, it > imports, but then clf() is only defined in the module, not interactively. The % commands are ipython magic commands. They are not valid Python syntax so you can't use them in a Python script. In a Python script you would use 'from pylab import *' for (roughly) the same effect: $ ipython Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.13.2 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: from pylab import * In [2]: clf Out[2]: > More confusing, if I do all the setup interactively, and the try to just run > my script, again, clf() [etc] don't work (don't appear to exist), even though > I can do them interactively. When you use %run it runs the script "externally". This is basically the same as typing 'python myscript.py' in the system terminal. In that case the script needs to import everything it wants to use. > There seems to be some sort of scoping problem ... or, put more correctly, my > problem is that I don't seem to understand the scoping, like, are %run > eval'ed in some closed context that doesn't work the same way as ipython > interactive? Is there any way to really do what I mean, which is: Please just > read in commands from that script (short of getting out and passing my script > through stdin to ipython?) I'm not sure if I understand what you mean but I usually %edit the script and closing the editor seems to just run the commands as if I typed them directly in. If you really want this kind of semi-interactive Matlab-style approach I suggest having a look at the Spyder IDE. Personally though I think it's bad to work this way in Python (and in Matlab) and I discourage my students from doing this. The interactive interpreter modes are great for testing short snippets of code or introspecting modules etc. However any real code should go in a real script. Using %edit for convenience while you write the script is fine but make sure that what you're creating is a real Python script that you can run normally with 'python myscript.py'. Spyder is also good for doing this. Otherwise all of your work, computation and plots are a mess and it becomes impossible to trace back to exactly how you produced everything to check your work or to fix it when it becomes apparent that you've screwed up. Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: howto check programs and C libraries
On 4 October 2013 10:30, David Palao wrote: > Hello, > I'm in charge of preparing a computer room for the practices of > "introduction to programming". > One of the tasks is checking that from all the computers in the room > one can execute some programs and link (and compile) against some > libraries. > My first idea was using Autotools (or cmake), but as I'm a big fan of > python, I was thinking how to do that with python, and I don't have a > clear solution yet. > I know that distutils includes the distutils.command.config module, > and I think it could do the job (when properly subclassed). > Do you have a better idea? I'm not very experienced with it but perhaps waf would be better for you: https://code.google.com/p/waf/ Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: hg.python.org: Server unresponsive and timeout
On 2 October 2013 23:25, Terry Reedy wrote: > On 10/2/2013 5:36 AM, Tae Wong wrote: >> >> This post is irrelevant from using Python; so it's an Internet server >> problem. >> >> When you try to connect to hg.python.org, the connection takes forever. > > > I believe hg.python.org is on a different machine than python.org. It has > occasionally been down, but works fine with Firefox. Sometimes connections > fail even if both endpoints are working. If you have a particular persistent > problem with hg.python.org, I suggest talking to your ISP. > > Cloning the CPython repository may take an hour or two if that is what you > are trying to do. It takes 15 minutes to clone with hg from hg.python.org on my machine. It takes 4 minutes on the same machine to clone the semi-official github mirror using git: 'git clone https://github.com/python/cpython.git' Those times are obviously affected by the fact that I have a very good internet connection at work: neither of the above operations comes close to the maximum bandwidth that I can access from some servers. Perhaps if there are problems with hg.python.org you might want to try the github mirror though. Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: Where does MySQLdb put inserted data?
On 10/04/2013 09:38 AM, F.R. wrote:
Hi,
As of late clipboard pasting into a terminal sometimes fails (a
known bug, apparently), I use MySQLdb to access MySQL tables. In
general this works just fine. But now I fail filling a new table. The
table exists. "mysql>EXPLAIN new_table;" explains and
"root@blackbox-one:/# sudo/find / -name 'new_table*'" finds
"/var/lib/mysql/fr/new_table.frm". So I do "cursor.executemany
('insert into new_table values (%s)' % format, data)". No error occurs
and "cursor.execute ('select * from new_table;')" returns the number
of records read, and "cursor.fetchall ()" returns all new records. All
looks fine, but "mysql>SELECT * FROM new_table;" produces an "Empty
set" and "sudo find / -name 'new_table*" still finds only the format
file, same as before.
Could it have to do with COMMIT. I believe I am using ISAM tables
(default?) and those don't recognize undo commands, right?. Anyway, an
experimental "cursor.execute ('COMMIT')" didn't make a difference. It
looks like MySQLdb puts the data into a cache and that cache should be
saved either by the OS or by me. Strange thing is that this is one
freak incident in an almost daily routine going back years and
involving thousands of access operations in and out acting
instantaneously. I seem to remember a similar case some time ago and
it also involved a new empty table.
Thanks for hints
Frederic
mysql> select version()
-> ;
+-+
| version() |
+-+
| 5.5.31-0ubuntu0.12.04.1 |
+-+
1 row in set (0.00 sec)
Thank you Chris, thank you Steven,
The suggestion to switch to PostgreSQL isn't lost on me. I have it
installed, but have been putting off the change, apprehensive of getting
slowed down by many annoying side effects for some time to come. This
may be the moment . . .
Off list? MySQL is. MySQLdb is not. Before I know which of the two
is the culprit, I don't know whether I'm off list or not and take the
risk, prepared to beg pardon if I am.
Frederic
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
Mark Janssen writes:
> def fact(n): return 1 if n <= 1 else n * fact(n-1)
>> class Strange:
>> ...
>> def __le__(dummy):
>> global fact
>> fact = someotherfun # this is "binding"
>> return false
>> You cannot prevent this in python.
> No, but you can't prevent a lot of bad moves in python. What you just
> did there is a total bonehead ("strange"?) of an idea.
I think allowing rebinding of function names is extremely strange, even
though it's easier to implement. I tend to agree with you on the quality
of the idea, but optimization has to take this into account (and give
up, usually).
-- Alain.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Where does MySQLdb put inserted data?
On Fri, Oct 4, 2013 at 8:05 PM, F.R. wrote: > Off list? MySQL is. MySQLdb is not. Before I know which of the two is > the culprit, I don't know whether I'm off list or not and take the risk, > prepared to beg pardon if I am. > Just to clarify: Off-topic means discussing stuff that isn't about Python; off-list means sending private emails, not to [email protected] / comp.lang.python. You're uncertain as to whether you're off-topic or not, but you're definitely on-list; and my previous mail to you was off-list, so people here are going to be a little confused, as they lack context. (I merely suggested that switching to PostgreSQL would quite probably be a worthwhile time investment.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
Neil Cerutti wrote: > On 2013-10-03, Duncan Booth wrote: >> It isn't hard to imagine adding a TAIL_CALL opcode to the >> interpreter that checks whether the function to be called is >> the same as the current function and if it is just updates the >> arguments and jumps to the start of the code block. > > Tail call optimization doesn't involve verification that the > function is calling itself; you just have to verfify that the > call is in tail position. You misunderstood me. As usually implemented tail call recursion doesn't require verifying that the function is calling itself, but in Python the function could be rebound so a check would be a necessary protection against this unlikely situation. Consider this Python: @some_decorator def fact(n, acc=1): if n <= 1: return acc return fact(n-1, n*acc) Is that tail recursion or not? You cannot tell whether or not that is tail recursion unless you know the definition of 'some_decorator' and even then the answer may vary from run to run. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Fri, Oct 4, 2013 at 4:16 AM, Duncan Booth wrote: > Neil Cerutti wrote: >> On 2013-10-03, Duncan Booth wrote: >>> It isn't hard to imagine adding a TAIL_CALL opcode to the >>> interpreter that checks whether the function to be called is >>> the same as the current function and if it is just updates the >>> arguments and jumps to the start of the code block. >> >> Tail call optimization doesn't involve verification that the >> function is calling itself; you just have to verfify that the >> call is in tail position. > > You misunderstood me. As usually implemented tail call recursion doesn't > require verifying that the function is calling itself, but in Python the > function could be rebound so a check would be a necessary protection > against this unlikely situation. Consider this Python: > > @some_decorator > def fact(n, acc=1): >if n <= 1: >return acc >return fact(n-1, n*acc) > > Is that tail recursion or not? > > You cannot tell whether or not that is tail recursion unless you know the > definition of 'some_decorator' and even then the answer may vary from run > to run. There is no doubt that it's a tail call. Whether it is recursion is irrelevant to optimizing it. The reason we talk about "tail call recursion" specifically is because the recursive case is the one that makes the optimization worthwhile, not because the recursion is necessary to perform the optimization. It is possible that fact is recursive but that some_decorator adds additional stack frames that are not tail calls and not optimizable. If this were the case, then the recursion would still eventually hit the stack limit, but there would still be benefit in optimizing the "fact" frames, as it would increase the allowable depth before the stack limit is reached. So I see no reason to check the identity of the called function before optimizing the tail call. -- https://mail.python.org/mailman/listinfo/python-list
Re: Where does MySQLdb put inserted data?
On 10/04/2013 12:11 PM, Chris Angelico wrote: On Fri, Oct 4, 2013 at 8:05 PM, F.R. wrote: Off list? MySQL is. MySQLdb is not. Before I know which of the two is the culprit, I don't know whether I'm off list or not and take the risk, prepared to beg pardon if I am. Just to clarify: Off-topic means discussing stuff that isn't about Python; off-list means sending private emails, not to [email protected] / comp.lang.python. You're uncertain as to whether you're off-topic or not, but you're definitely on-list; and my previous mail to you was off-list, so people here are going to be a little confused, as they lack context. (I merely suggested that switching to PostgreSQL would quite probably be a worthwhile time investment.) ChrisA I shall switch and give you credit for the impulse in addition to the terminological clarification on being off something or other . . . Frederic -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Fri, Oct 4, 2013 at 4:41 AM, Ian Kelly wrote: > There is no doubt that it's a tail call. Whether it is recursion is > irrelevant to optimizing it. The reason we talk about "tail call > recursion" specifically is because the recursive case is the one that > makes the optimization worthwhile, not because the recursion is > necessary to perform the optimization. > > It is possible that fact is recursive but that some_decorator adds > additional stack frames that are not tail calls and not optimizable. > If this were the case, then the recursion would still eventually hit > the stack limit, but there would still be benefit in optimizing the > "fact" frames, as it would increase the allowable depth before the > stack limit is reached. So I see no reason to check the identity of > the called function before optimizing the tail call. On the other hand, if you start optimizing every tail call and not just the recursive functions, then I can see where that could start to get problematic for debugging -- as arbitrary functions get removed from the stack traces just because they happened to end in tail calls. -- https://mail.python.org/mailman/listinfo/python-list
Image manipulation
Is there a way using the python 3.3.2 whidout any additional downloaded moduls, to get a pixels RGB value? -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Thursday, October 3, 2013 10:57:48 PM UTC+5:30, Ravi Sahni wrote: > On Wed, Oct 2, 2013 at 10:46 AM, rusi wrote: > > 4. There is a whole spectrum of such optimizaitons -- > > 4a eg a single-call structural recursion example, does not need to push > > return address on the stack. It only needs to store the recursion depth: > > > > If zero jump to outside return add; if > 0 jump to internal return address > > > > 4b An example like quicksort in which one call is a tail call can be > > optimized with your optimization and the other, inner one with 4a above > > > I am interested in studying more this 'whole spectrum of optimizations' > Any further pointers? Mmm… Bummer… There was a book having these -- at least 5-6 different optimizations of which tail-call was the most obvious. Maybe author was McGettrick dont remember for sure... Probably 20 years now! I'll try and re-remember them and post. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Fri, 04 Oct 2013 11:49:26 +0200, Alain Ketterlin wrote: > I think allowing rebinding of function names is extremely strange, It's not, it's quite common. Functions in Python are first-class values, and we can do things like this: from somelibrary import somethingwithalonglongname as shortname def inorder(tree, op=print): # Walk the tree in infix order, doing op to each node. process(tree.left, op) op(tree.payload) process(tree.right, op) _len = len def len(obj): do_something_first() return _len(obj) Now, the first two aren't the same sort of function-rebinding that you're talking about, or that were shown in your post, but the third is. What is unusual though is rebinding a function from within itself: def func(arg): global func do_this(arg) def func(arg): do_that(arg) but it's legal and it sometimes can be useful, although it counts as "clever code", possibly "too clever". -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
Duncan Booth writes: > Neil Cerutti wrote: > > On 2013-10-03, Duncan Booth wrote: > >> It isn't hard to imagine adding a TAIL_CALL opcode to the > >> interpreter that checks whether the function to be called is > >> the same as the current function and if it is just updates the > >> arguments and jumps to the start of the code block. > > > > Tail call optimization doesn't involve verification that the > > function is calling itself; you just have to verfify that the > > call is in tail position. > > You misunderstood me. As usually implemented tail call recursion > doesn't require verifying that the function is calling itself, but > in Python the function could be rebound so a check would be a > necessary protection against this unlikely situation. Consider this > Python: > > @some_decorator > def fact(n, acc=1): >if n <= 1: >return acc >return fact(n-1, n*acc) > > Is that tail recursion or not? > > You cannot tell whether or not that is tail recursion unless you > know the definition of 'some_decorator' and even then the answer may > vary from run to run. Ignoring the decorator, fact(n-1, n*acc) is in a tail position because it follows the keyword return. It doesn't matter what function fact is at the time: the remaining action in the caller is to return. Tail positions, with respect to enclosing code, are defined syntactically. -- https://mail.python.org/mailman/listinfo/python-list
Re: howto check programs and C libraries
On 4/10/2013 05:30, David Palao wrote: > Hello, > I'm in charge of preparing a computer room for the practices of > "introduction to programming". > One of the tasks is checking that from all the computers in the room > one can execute some programs and link (and compile) against some > libraries. > My first idea was using Autotools (or cmake), but as I'm a big fan of > python, I was thinking how to do that with python, and I don't have a > clear solution yet. > I know that distutils includes the distutils.command.config module, > and I think it could do the job (when properly subclassed). > Do you have a better idea? I don't have any specific tool in mind, but I'd suggest that you really need to run the tool on only one of the machines, and run a separate tool on them all that assures that they are identical, presumably made that way by wiping each and copying from a master That assumes the hardware is close enough to identical to make this practical. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
Ian Kelly wrote: > On Fri, Oct 4, 2013 at 4:41 AM, Ian Kelly wrote: >> There is no doubt that it's a tail call. Whether it is recursion is >> irrelevant to optimizing it. The reason we talk about "tail call >> recursion" specifically is because the recursive case is the one that >> makes the optimization worthwhile, not because the recursion is >> necessary to perform the optimization. >> >> It is possible that fact is recursive but that some_decorator adds >> additional stack frames that are not tail calls and not optimizable. >> If this were the case, then the recursion would still eventually hit >> the stack limit, but there would still be benefit in optimizing the >> "fact" frames, as it would increase the allowable depth before the >> stack limit is reached. So I see no reason to check the identity of >> the called function before optimizing the tail call. > > On the other hand, if you start optimizing every tail call and not > just the recursive functions, then I can see where that could start to > get problematic for debugging -- as arbitrary functions get removed > from the stack traces just because they happened to end in tail calls. Quite so. Losing some stack frames in the traceback because tail recursion was optimised is probably no big deal. Losing arbitrary stack frames because of a more widespread tail call optimisation would not IMHO fit with the spirit of Python except possibly as an optional optimisation that was off by default. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: howto check programs and C libraries
On Fri, Oct 4, 2013 at 3:00 PM, David Palao wrote: > Hello, > I'm in charge of preparing a computer room for the practices of > "introduction to programming". > One of the tasks is checking that from all the computers in the room > one can execute some programs and link (and compile) against some > libraries. > My first idea was using Autotools (or cmake), but as I'm a big fan of > python, I was thinking how to do that with python, and I don't have a > clear solution yet. > I know that distutils includes the distutils.command.config module, > and I think it could do the job (when properly subclassed). > Do you have a better idea? I have ruby on rails friends who speak of capistrano and puppet. google puppet python gives me : http://stackful-dev.com/cuisine-the-lightweight-chefpuppet-alternative If you find it good I shall be interested to know. -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Tuesday, October 1, 2013 5:06:38 PM UTC-5, Ben Finney wrote: > This is an unmoderated forum, so we have occasional spates of persistent > > nuisances, and those who respond with the maturity level and impulse > > control of an average six-year-old. Hey! That's so degrading! I don't know many six-year-olds (and certainly not mine, but maybe they're just not average) who would continue to respond in the same fashion that the OP of *this* thread did! ;-) -W -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
Op 03-10-13 13:30, Steven D'Aprano schreef: > On Thu, 03 Oct 2013 09:01:29 +0200, Antoon Pardon wrote: > >> You don't >> follow the principle of treating others in the way you hope to be >> treated if you were in their shoes. > [...] >> Suppose you develop a new >> interest in which you are now the newbie and you go to a newsgroup or >> forum where as a nebie you ask a poor question. Are you hoping they will >> answer with sarcasm? I doubt that very much. > > Then you would be wrong. You don't know me very well at all. > > If I asked a dumb question -- not an ignorant question, but a dumb > question -- then I hope somebody will rub my nose in it. Sarcasm strikes > me as a good balance between being too namby-pamby to correct me for > wasting everyone's time, and being abusive. You are contradicting yourself with previous contributions. If you yourself want to be treated with sarcasm when you ask a poor question and you follow the priciple of trying to treat people the same way as you like to be treated should you be in their shoes. Then it doesn't make sense that you should judge yourself as not living up to your ideals because of having a tendency to react to newbies' poor questions with sarcasm, as you did earlier. That tendency would then make you live up to your ideals. I have the impression you haven't thought this through much and are just making it up as you go along. > And quite frankly, although I might *prefer* a gentle request asking for > more information, I might *need* something harsher for the lesson to > really sink in. Negative reinforcement is a legitimate teaching tool, > provided it doesn't cross the line into abuse. But need was orginally not a consideration. You certainly never seem to consider Nikos might need something harsher than a polite answer, labeling almost any criticism almost automaticcaly as hate. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wednesday, October 2, 2013 5:43:32 AM UTC-5, Ferrous Cranus wrote: > > I only re-ask the same thing if: > > > 1. Di not understood what was provided or proposed to me as being a solution > > 2. Still feel that that the solution provided to me doesn't meet my > needs and should have been re-written in a different way. Nevertheless > we are all improving, especially the newbies, by seeing alternative way, > best methods and wise practices of writing code for the specific problem > and pick the one that does the job best. > If you feel that the provided solution doesn't meet your needs then the *most likely* answer is that you have asked the wrong question. Rather than, say, posting a new thread (unless your new question is clearly different and mostly unrelated), the appropriate course of action is to say something like, "Hey, apparently I'm asking the wrong question, because all these answers are about frobnosticating, but I really wanted to foo the baz." If you don't acknowledge that you goofed up, you come across as arrogant or ignorant (or both). -W -- https://mail.python.org/mailman/listinfo/python-list
API for custom Unicode error handlers
I have some custom Unicode error handlers, and I'm looking for advice on
the right API for dealing with them.
I have a module containing custom Unicode error handlers. For example:
# Python 3
import unicodedata
def namereplace_errors(exc):
c = exc.object[exc.start]
try:
name = unicodedata.name(c)
except (KeyError, ValueError):
n = ord(c)
if n <= 0x:
replace = "\\u%04x"
else:
assert n <= 0x10
replace = "\\U%08x"
replace = replace % n
else:
replace = "\\N{%s}" % name
return replace, exc.start + 1
Before I can use the error handler, I need to register it using this:
import codecs
codecs.register_error('namereplace', namereplace_errors)
And now:
py> 'abc\u04F1'.encode('ascii', 'namereplace')
b'abc\\N{CYRILLIC SMALL LETTER U WITH DIAERESIS}'
Now, my question:
Should the module holding the error handlers automatically register them?
In other words, if I do:
import error_handlers
just importing it will have the side-effect of registering the error
handlers. Normally, I dislike imports that have side-effects of this
sort, but I'm not sure that the alternative is better, that is, to put
responsibility on the caller to register some, or all, of the handlers:
import error_handlers
error_handlers.register(error_handlers.namereplace_errors)
error_handlers.register_all()
As far as I know, there is no way to find out what error handlers are
registered, and no way to deregister one after it has been registered.
Which API would you prefer if you were using this module?
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
Re: ipy %run noob confusion
Thank you. This is extremely helpful. The key that I was missing is that it's running them outside of the ipy context. I also discovered that if you call the script .ipy instead of .py, it actually does more or less what I was expecting -- that is, it allows magic commands, and I got the thing working as desired through this means. I do appreciate the concern that my script should be "real" python, and I would aim for that eventually, but while I'm experimenting, it's useful to be able to have the interactive and script work the same way. I'm happy to "real-ify" it later. BTW, I generally work the opposite way than %edit: I code in emacs, and have a shell that's running ipy. Actually ipy is bad at this because it sends all sorts of terminal crap that I can probably get rid of somehow, but working this way has many advantages, not the least of which is that you don't have to fire up editors over and over (my editor context is primary), and I get an automatic log of my whole session in the shell buffer. This mode has served me well using regular python, because I didn't have the .ipy v. .py problem, but when I started into ipyton, things no longer worked. But your guidance (and others) have help deconfuse me on this. Thanks again! -- https://mail.python.org/mailman/listinfo/python-list
Re: Image manipulation
On 10/04/2013 03:52 AM, [email protected] wrote: Is there a way using the python 3.3.2 whidout any additional downloaded moduls, to get a pixels RGB value? No (I guess). If you want a better answer, then you'll have to give us a *much* better question. Get a pixel from *what*? (screen? image on disk? image on web page? printed image on paper? ...?) On what operating system? Using what kind of a graphics/imaging hardware/software? How are said pixels being written? Please understand how broad the term pixel is and how little information your question has provided. Try again with a full description of what you want, and we'll try to provide a useful answer. Gary Herron -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple scripts versus single multi-threaded script
On 2013-10-03, Roy Smith wrote: > Threads are lighter-weight. That means it's faster to start a new > thread (compared to starting a new process), and a thread consumes > fewer system resources than a process. That's true, but the extent to which it's true varies considerably from one OS to another. Starting processes is typically very cheap on Unix systems. On Linux a thread and a process are actually both started by the same system call, and the only significant difference is how some of the new page descriptors are set up (they're copy-on-write instead of shared). On other OSes, starting a process is _way_ more expensive/slow than starting a thread. That was very true for VMS, so one suspects it might also be true for its stepchild MS-Window. -- Grant Edwards grant.b.edwardsYow! RELATIVES!! at gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: compare two list of dictionaries
On 04/10/2013 03:29, Mohan L wrote:
[snip]
output1=[
{'count': 3 , 'ip': 'xxx.xx.xxx.1'},
{'count': 4, 'ip': 'xxx.xx.xxx.2'},
{'count': 8, 'ip': 'xxx.xx.xxx.3'},
{'count': 10, 'ip': 'xxx.xx.xxx.4'},
{'count': 212, 'ip': 'hostname1'},
{'count': 27, 'ip': 'hostname2'},
{'count': 513, 'ip': 'hostname3'},
{'count': 98, 'ip': 'hostname4'},
{'count': 1, 'ip': 'hostname10'},
{'count': 2, 'ip': 'hostname8'},
{'count': 3, 'ip': 'xxx.xx.xxx.11'},
{'count': 90, 'ip': 'xxx.xx.xxx.12'},
{'count': 12, 'ip': 'xxx.xx.xxx.13'},
{'count': 21, 'ip': 'xxx.xx.xxx.14'},
{'count': 54, 'ip': 'xxx.xx.xxx.15'},
{'count': 34, 'ip': 'xxx.xx.xxx.16'},
{'count': 11, 'ip': 'xxx.xx.xxx.17'},
{'count': 2, 'ip': 'xxx.xx.xxx.18'},
{'count': 19, 'ip': 'xxx.xx.xxx.19'},
{'count': 21, 'ip': 'xxx.xx.xxx.20'},
{'count': 25, 'ip': 'xxx.xx.xxx.21'},
{'count': 31, 'ip': 'xxx.xx.xxx.22'},
{'count': 43, 'ip': 'xxx.xx.xxx.23'},
{'count': 46, 'ip': 'xxx.xx.xxx.24'},
{'count': 80, 'ip': 'xxx.xx.xxx.25'},
{'count': 91, 'ip': 'xxx.xx.xxx.26'},
{'count': 90, 'ip': 'xxx.xx.xxx.27'},
{'count': 10, 'ip': 'xxx.xx.xxx.28'},
{'count': 3, 'ip': 'xxx.xx.xxx.29'}]
output2=(('INNCHN01','xxx.xx.xxx.11'),
('HYDRHC02', 'xxx.xx.xxx.12'),
('INNCHN03','xxx.xx.xxx.13'),
('MUMRHC01','xxx.xx.xxx.14'),
('n/a','xxx.xx.xxx.15'),
('INNCHN05','xxx.xx.xxx.16'),
('hostname1','n/a'),
('hostname2','n/a'),
('hostname10',''),
('hostname8',''),
('hostname200','xxx.xx.xxx.200'),
('hostname300','xxx.xx.xxx.400'),
)
## 1).
## Create a dict from output1 in which the key is the ip and the value
is the count.
mongodb_data={}
for doc in output1:
mongodb_data.update({doc['ip']:doc['count']})
A simpler way is:
mongodb_data = {}
for doc in output1:
mongodb_data[doc['ip']] = doc['count']
## Create a set from output2 containing all the hostnames and ip_addrs.
all_hostname_ip_set=set(list(sum(output2, (
## Get the intersection of the keys of the dict with the set.
key_set=set(mongodb_data.keys())
int_keys=key_set & all_hostname_ip_set
# Print the entries of the dict for each member of the intersection.
print "---intersection-"
for key in int_keys:
print key,mongodb_data[key]
## 2).
## Get the difference between the keys of the dict and the intersection.
deff_keys=key_set - all_hostname_ip_set
## Print the entries of the dict for each member of the difference.
print "---difference---"
for key in deff_keys:
print key,mongodb_data[key]
$ ./demo.py
---intersection-
xxx.xx.xxx.11 3
xxx.xx.xxx.12 90
xxx.xx.xxx.13 12
xxx.xx.xxx.14 21
xxx.xx.xxx.15 54
xxx.xx.xxx.16 34
hostname2 27
hostname1 212
hostname10 1
hostname8 2
---difference---
xxx.xx.xxx.29 3
xxx.xx.xxx.28 10
xxx.xx.xxx.17 11
xxx.xx.xxx.18 2
xxx.xx.xxx.19 19
xxx.xx.xxx.23 43
xxx.xx.xxx.22 31
xxx.xx.xxx.25 80
xxx.xx.xxx.24 46
xxx.xx.xxx.27 90
xxx.xx.xxx.26 91
xxx.xx.xxx.2 4
xxx.xx.xxx.21 25
hostname3 513
hostname4 98
xxx.xx.xxx.4 10
xxx.xx.xxx.20 21
xxx.xx.xxx.1 3
xxx.xx.xxx.3 8
3). Ip address with is there only in output2 dictionary.
xxx.xx.xxx.200
xxx.xx.xxx.400
1. Create a set from output2 containing all the ip_addrs
2. Get the difference between the set and the keys of the dict created
from output1.
I have one problem here. I want to compare the output2 (hostname or ip
address) with output1 'ip' values (i.e., either hostname or ip address
of output2 does not matching the ip dict key in output1 then I want to
print either hostname or ip address from output2).
You already have the output1 'ip' values (the keys of mongodb_data) and
the entries of output2 (all_hostname_ip_set). Just find the set
difference.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Why didn't my threads exit correctly ?
Thanks for your reply, MRAB.
I've seen that the child thread has been stoped, it just died in the
queue.If I want the queue be empty, I must use queue.get() to dequeue and
clean it, but I didn't do that.
I've implement the thread using List now, thanks again.
On Fri, Oct 4, 2013 at 2:25 AM, MRAB wrote:
> On 03/10/2013 18:37, 李洛 wrote:
>
>> Hi list,
>> I write an example script using threading as follow.
>> It look like hang when the list l_ip is empty. And any suggestion with
>> debug over the threading in Python ?
>>
>>1 #!/usr/bin/env python
>>2 # -*- coding: utf-8 -*-
>>3 import re
>>4 import os
>>5 import threading
>>6 from Queue import Queue
>>7 from time import sleep
>>8
>>9 l_ip = []
>> 10 l_result = []
>> 11 result = re.compile(r"[1-3] received")
>> 12
>> 13 class ping(threading.Thread):
>> 14 """ """
>> 15 def __init__(self, l_ip, l_result):
>> 16 threading.Thread.__init__(**self)
>> 17 self.l_ip = l_ip
>> 18 #self.l_result = l_result
>> 19
>> 20 def run(self):
>> 21 """ """
>> 22 while True:
>> 23 try:
>> 24 ip = self.l_ip.pop()
>> 25 except IndexError as e:
>> 26 print e
>> 27 break
>> 28 ping_out = os.popen(''.join(['ping -q -c3 ',ip]), 'r')
>> 29 print 'Ping ip:%s' % ip
>> 30 while True:
>> 31 line = ping_out.readline()
>> 32 if not line: break
>> 33 if result.findall(line):
>> 34 l_result.append(ip)
>> 35 break
>> 36
>> 37 queue = Queue()
>> 38
>> 39 for i in range(1,110):
>> 40 l_ip.append(''.join(['192.168.**1.', str(i)]))
>> 41 for i in xrange(10):
>> 42 t = ping(l_ip, l_result)
>> 43 t.start()
>> 44 queue.put(t)
>> 45 queue.join()
>> 46 print "Result will go here."
>> 47 for i in l_result:
>> 48 print 'IP %s is OK' % i
>>
>> queue.join() will block until the queue is empty, which is never is!
>
> You're putting the workers in the queue, whereas the normal way of
> doing it is to put them into a list, the inputs into a queue, and the
> outputs into another queue. The workers then 'get' from the input
> queue, do some processing, and 'put' to the output queue.
>
> --
> https://mail.python.org/**mailman/listinfo/python-list
>
--
All the best!
http://luolee.me
--
https://mail.python.org/mailman/listinfo/python-list
Re: API for custom Unicode error handlers
On Fri, Oct 4, 2013 at 11:56 PM, Steven D'Aprano wrote: > Should the module holding the error handlers automatically register them? > In other words, if I do: > > import error_handlers > > just importing it will have the side-effect of registering the error > handlers. Normally, I dislike imports that have side-effects of this > sort, but I'm not sure that the alternative is better, that is, to put > responsibility on the caller to register some, or all, of the handlers: > > import error_handlers > error_handlers.register(error_handlers.namereplace_errors) > error_handlers.register_all() Caveat: I don't actually use codecs much, so I don't know the specifics. I'd be quite happy with importing having a side-effect here. If you import a module that implements a numeric type, it should immediately register itself with the Numeric ABC, right? This is IMO equivalent to that. > As far as I know, there is no way to find out what error handlers are > registered, and no way to deregister one after it has been registered. The only risk that I see is of an accidental collision. Having a codec registered that you don't use can't hurt (afaik). Is there any mechanism for detecting a name collision? If not, I wouldn't worry about it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: API for custom Unicode error handlers
On 10/04/2013 06:56 AM, Steven D'Aprano wrote: Should the module holding the error handlers automatically register them? I think it should. Registration only needs to happen once, the module is useless without being registered, no threads nor processes are being started, and the only reason to import the module is to get the functionality... isn't it? What about help(), sphynx (sp?), or other introspection tools? This sounds similar to cgitb -- another module which you only import if you want the html'ized traceback, and yet it requires a separate cgitb.enable() call... I change my mind, it shouldn't. Throw in a .enable() function and call it good. :) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: API for custom Unicode error handlers
04.10.13 20:22, Chris Angelico написав(ла): I'd be quite happy with importing having a side-effect here. If you import a module that implements a numeric type, it should immediately register itself with the Numeric ABC, right? This is IMO equivalent to that. There is a difference. You can't use a numeric type without importing a module, but you can use error handler registered outside of your module. This leads to subtle bugs. Let the A module imports error_handlers and uses error handle. The module B uses error handle but doesn't import error_handlers. C.py imports A and B and all works. D.py imports B and A and fails. -- https://mail.python.org/mailman/listinfo/python-list
Help wanted: Writing a PMI Project Management system
I'm looking for anyone who has an interest in project management; workable Python design and programming skills; and wants to code for an open source Project Management system. Having used Redmine, Launchpad, Trak, OpenProj, and so on, I've found there's no good PM tools. Microsoft Project and Oracle PM are even kind of crap. The issue I have is that none of these are really in line with modern PM. The PMBOK and various practice standards outline something very different from what's available. For example: Redmine has the concept of Projects and Subprojects; but it doesn't have the concept of a Program, and instead follows the common open source model by which a "Project" is all on-going effort of a deliverable. Calling "Mozilla Firefox" a project is technically incorrect. "Mozilla Firefox" is the deliverable of a Program (called Mozilla Firefox), an ongoing effort to meet a business need (in this case, the "business need" is the collective desire to produce a Web browser). Mozilla Firefox 18 is a Project; Mozilla Firefox 19 is a Project; and so on. More Projects will be added to the Program; long-standing bugs in Mozilla Firefox are Program Issues, and a particular Project (i.e. Mozilla Firefox 21) may include as a requirement "Correct and close bug #55995" or such. I've been trying to write a technically correct Project Management software system that adheres to the PMBOK 5e (released January 2013), but I am a crappy software designer. I can code, some, but I don't know Python well enough; I don't know how to accomplish some design aspects (like modularity--the ability to extend via drop-in plug-ins instead of by tightly integrated code) and I don't know much about software design at all anyway. I know how to translate procedural concepts into code in any language I can code in to the best of my understanding of the language--some people think this makes them good programmers; they create absolute garbage, and I have no intent of being that guy. I'll code, but I'll code based on the design of somebody actually competent, thanks. So I guess what I want is to find people who are: * Interested in Project Management as a concept * Skilled in application design and Python * Interested in putting these two things together and contributing to a program to develop a technically correct Project Management software suite In open source software development, the primary compensation is self-enrichment: Developers are attracted by the chance to learn something new, to enhance their skills, to contribute to something they feel is worthwhile, or to work on something they simply enjoy working on. Thus I need to find people who go, "That looks interesting." Where do I find? >From a planning perspective, the initial goal is to create the four main >modules: * Project Management * Program Management * Portfolio Management * Work Breakdown Structure Projects are a temporary effort to produce a deliverable. Programs are an ongoing effort to address a business or organizational need, and may include other programs and projects. Portfolios are collections of Projects, Programs, and Portfolios under the control of an organization. A business may have its Portfolio, containing its Marketing and MIS Portfolios, which each contain Programs (for Marketing or MIS) that contain Projects and other Programs. A department may even have sub-portfolios: the MIS Portfolio may contain Networking Portfolio, Programming Portfolio, and Systems Portfolio for the three departments under MIS. Each Project has a Work Breakdown Structure. Every element is a deliverable, so something that must actually exist. The Project is itself the sole top-level element, for example: 1. Work Breakdown Structure Module The process of Decomposition is used to break down the project into manageable work. Work is "Manageable" when it can be understood; breaking it down further gives no gain and causes increased management overhead, so is wasteful. There are many decomposition strategies such as top-down, bottom-up, brainstorm, and fishbone; they are usually combined (I favor top-down, then bottom-up). The first level of decomposition can go in any direction. It is often recommended as decomposition by phase (Design, Implementation, Testing...) or by major deliverables (Drive System, Engine, Wheels, Suspension...), or combination means. 1. Work Breakdown Structure Module 1.1 Project Management 1.2 Design 1.3 Implementation 1.4 Testing 1.5 Release These are further broken down. 1. Work Breakdown Structure Module 1.1 Project Management 1.1.1 Work Breakdown Structure 1.1.2 Meetings 1.2 Design 1.2.1 Document Schema 1.2.2 UI 1.2.2.1 Outline View 1.2.2.2 Table View 1.2.2.3 Graphical View 1.3 Implementation 1.3.1 Back-End 1.3.1.1 Storage Class 1.3.1.2 Data Rendering 1.3.2 Front-End 1.3.2.1 Views 1.3.2.1.1 Outline View 1.3.2.1.2 Table View 1.3.2.1.3 Graphical View 1.4 Testin
Re: compare two list of dictionaries
On 10/03/2013 09:11 AM, Mohan L wrote:
Dear All,
I have two list of dictionaries like below:
In the below dictionaries the value of ip can be either hostname or ip address.
output1=[
{'count': 3 , 'ip': 'xxx.xx.xxx.1'},
{'count': 4, 'ip': 'xxx.xx.xxx.2'},
{'count': 8, 'ip': 'xxx.xx.xxx.3'},
{'count': 10, 'ip': 'xxx.xx.xxx.4'},
{'count': 212, 'ip': 'hostname1'},
{'count': 27, 'ip': 'hostname2'},
{'count': 513, 'ip': 'hostname3'},
{'count': 98, 'ip': 'hostname4'},
{'count': 1, 'ip': 'hostname10'},
{'count': 2, 'ip': 'hostname8'},
{'count': 3, 'ip': 'xxx.xx.xxx.11'},
{'count': 90, 'ip': 'xxx.xx.xxx.12'},
{'count': 12, 'ip': 'xxx.xx.xxx.13'},
{'count': 21, 'ip': 'xxx.xx.xxx.14'},
{'count': 54, 'ip': 'xxx.xx.xxx.15'},
{'count': 34, 'ip': 'xxx.xx.xxx.16'},
{'count': 11, 'ip': 'xxx.xx.xxx.17'},
{'count': 2, 'ip': 'xxx.xx.xxx.18'},
{'count': 19, 'ip': 'xxx.xx.xxx.19'},
{'count': 21, 'ip': 'xxx.xx.xxx.20'},
{'count': 25, 'ip': 'xxx.xx.xxx.21'},
{'count': 31, 'ip': 'xxx.xx.xxx.22'},
{'count': 43, 'ip': 'xxx.xx.xxx.23'},
{'count': 46, 'ip': 'xxx.xx.xxx.24'},
{'count': 80, 'ip': 'xxx.xx.xxx.25'},
{'count': 91, 'ip': 'xxx.xx.xxx.26'},
{'count': 90, 'ip': 'xxx.xx.xxx.27'},
{'count': 10, 'ip': 'xxx.xx.xxx.28'},
{'count': 3, 'ip': 'xxx.xx.xxx.29'}]
In the below dictionaries have either hostname or ip or both.
output2=(
{'hostname': 'INNCHN01', 'ip_addr': 'xxx.xx.xxx.11'},
{'hostname': 'HYDRHC02', 'ip_addr': 'xxx.xx.xxx.12'},
{'hostname': 'INNCHN03', 'ip_addr': 'xxx.xx.xxx.13'},
{'hostname': 'MUMRHC01', 'ip_addr': 'xxx.xx.xxx.14'},
{'hostname': 'n/a', 'ip_addr': 'xxx.xx.xxx.15'},
{'hostname': 'INNCHN05', 'ip_addr': 'xxx.xx.xxx.16'},
{'hostname': 'hostname1', 'ip_addr': 'n/a'},
{'hostname': 'hostname2', 'ip_addr': 'n/a'},
{'hostname': 'hostname10', 'ip_addr': ''},
{'hostname': 'hostname8', 'ip_addr': ''},
{'hostname': 'hostname200', 'ip_addr': 'xxx.xx.xxx.200'},
{'hostname': 'hostname300', 'ip_addr': 'xxx.xx.xxx.400'},
)
trying to get the following difference from the above dictionary
1). compare the value of 'ip' in output1 dictionary with either 'hostname' and
'ip_addr' output2 dictionary and print their
intersection. Tried below code:
for doc in output1:
for row in output2:
if((row["hostname"] == doc["ip"]) or (row["ip_addr"] ==
doc["ip"])):
print doc["ip"],doc["count"]
*output:*
hostname1 212
hostname2 27
hostname10 1
hostname8 2
xxx.xx.xxx.11 3
xxx.xx.xxx.12 90
xxx.xx.xxx.13 12
xxx.xx.xxx.14 21
xxx.xx.xxx.15 54
xxx.xx.xxx.16 34
2). need to print the below output if the value of 'ip' in output1 dictionary
is not there in in output2 dictionary(ip/hostname
which is there in output1 and not there in output2):
xxx.xx.xxx.1 3
xxx.xx.xxx.2 4
xxx.xx.xxx.3 8
xxx.xx.xxx.4 10
hostname3 513
hostname4 98
xxx.xx.xxx.17 11
xxx.xx.xxx.18 2
xxx.xx.xxx.19 19
xxx.xx.xxx.20 21
xxx.xx.xxx.21 25
xxx.xx.xxx.22 31
xxx.xx.xxx.23 43
xxx.xx.xxx.24 46
xxx.xx.xxx.25 80
xxx.xx.xxx.26 91
xxx.xx.xxx.27 90
xxx.xx.xxx.28 10
xxx.xx.xxx.29 3
3). Ip address with is there only in output2 dictionary.
xxx.xx.xxx.200
xxx.xx.xxx.400
Any help would be really appreciated. Thank you
Thanks
Mohan L
There is a bit of work that can be consolidated
to help both case 2 and 3. Then both cases are
a little more straightforward:
##
import itertools
inside_out = {x['ip']: x for x in output1}
set1 = set(inside_out.keys())
### CASE 2 ###
set2 = set(itertools.chain.from_iterable([x.values() for x in output2]))
for name in set1 - set2:
print name, inside_out[name]['count']
### CASE 3 ###
set2 = set([x['ip_addr'] for x in output2])
print "\n".join(set2 - set1)
--
https://mail.python.org/mailman/listinfo/python-list
Re: API for custom Unicode error handlers
04.10.13 16:56, Steven D'Aprano написав(ла):
I have some custom Unicode error handlers, and I'm looking for advice on
the right API for dealing with them.
I have a module containing custom Unicode error handlers. For example:
# Python 3
import unicodedata
def namereplace_errors(exc):
c = exc.object[exc.start]
try:
name = unicodedata.name(c)
except (KeyError, ValueError):
n = ord(c)
if n <= 0x:
replace = "\\u%04x"
else:
assert n <= 0x10
replace = "\\U%08x"
replace = replace % n
else:
replace = "\\N{%s}" % name
return replace, exc.start + 1
I'm planning to built this error handler in 3.4 (see
http://comments.gmane.org/gmane.comp.python.ideas/21296).
Actually Python implementation should looks like:
def namereplace_errors(exc):
if not isinstance(exc, UnicodeEncodeError):
raise exc
replace = []
for c in exc.object[exc.start:exc.end]:
try:
replace.append(r'\N{%s}' % unicodedata.name(c))
except KeyError:
n = ord(c)
if n < 0x100:
replace.append(r'\x%02x' % n)
elif n < 0x1:
replace.append(r'\u%04x' % n)
else:
replace.append(r'\U%08x' % n)
return ''.join(replace), exc.end
Now, my question:
Should the module holding the error handlers automatically register them?
This question interesting me too.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On 10/4/2013 6:46 AM, Ian Kelly wrote: On the other hand, if you start optimizing every tail call and not just the recursive functions, then I can see where that could start to get problematic for debugging -- as arbitrary functions get removed from the stack traces just because they happened to end in tail calls. The idea of CPython space-optimizing tail calls when the call is made has been suggested on python-ideas. Guido verified that it is technically possible with the current bytecode interpreter but rejected it because it would arbitrarily mess up stack traces. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
Ravi Sahni writes: > I find this real confused!! Why they are answering then?!?! > As far as I can make out everyone who is answering (helping!) doing it > frustratation and disgust. But still they keep answering and > answering!! I answered him because I wanted to help him. I also find it interesting to solve Python problems. I did not like Nikos' arrogance, ignorance and his refusal to use perfectly good solutions. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On 10/4/2013 5:49 AM, Alain Ketterlin wrote:
I think allowing rebinding of function names is extremely strange,
Steven already countered the 'is extremely strange' part by showing that
such rebinding is common, generally useful, and only occasionally dodgy
and a candidate for being blocked.
I want to consider here what it would mean to concretely implement the
abstract notion 'disallow rebinding of function names' and show what
would be behind calling the idea 'not feasible'.
1. A 'name' is not a 'function name' unless the name is bound, at
runtime, to a 'function'.
2. A 'function' in Python is not just one class but any callable object
-- with with a __call__ methods. That comprises an unbounded set.
3. Python does not mandate how namespaces are implemented. CPython uses
both dicts and, for function local namespaces, internal C arrays. So
'names' in code can become either string keys for dicts or integer
indexes for arrays.
4. Rebinding can be explicit ('='), implicit ('import', 'class', 'def'),
*or hidden* (globals('a') = 1; ob.__dict__('a') = 1). The 'hidden'
methods are intentional as they are sometimes needed*. In CPython,
these forms remain different in the byte code, but it could be
otherwise. The point is that is may or may not be possible for the
interpreter to even recognize a 'rebinding' in order to apply any
rebinding blocking rule.
* There is no trick (that I know of) for hidden rebinding of function
locals and nonlocals (short of using ctypes), but I am not sure that
this is a language guarantee. However, I an sure that the absence is
intentional.
> even though it's easier to implement.
No kidding.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: API for custom Unicode error handlers
On 10/4/2013 3:35 PM, Serhiy Storchaka wrote: 04.10.13 16:56, Steven D'Aprano написав(ла): I have some custom Unicode error handlers, and I'm looking for advice on the right API for dealing with them. I'm planning to built this error handler in 3.4 (see http://comments.gmane.org/gmane.comp.python.ideas/21296). Should the module holding the error handlers automatically register them? This question interesting me too. I did not respond on the p-i thread, but +1 for 'namereplace' also. Like others, I would prefer auto-register unless that creates a problem. If it is a problem, perhaps the registry mechanism needs improvement. On the other hand, it is it built-in, it will be pre-registered. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Hyper-spacial ray-tracer
On 10/04/2013 04:23 PM, Tony the Tiger wrote: On Wed, 02 Oct 2013 17:05:32 -0400, Rouslan Korneychuk wrote: game Sorry, but that sounds awful. I hate games. This... isn't a game or even related to gaming. Is it because of the use of Pygame that you thought it was. I use Pygame because it's a wrapper for SDL, which gives you cross-platform graphics, input and even thread support, and because the additional drawing and font modules are useful for prototyping and implementing user-interfaces for navigating higher-dimensional space. The point of this was to explore the concept of hyperspace, which is a mathematical curiosity and also has relevance in theoretical physics. One idea I had for this was to simulate some sort of 3D scene involving physics (probably in another program, such as Blender), take the resulting coordinates of the geometry at every time interval and plot it as one 4D static scene. Every pair of connected vertexes would be extruded from one instant in time, to the next, so each object is a continuous 4D extrusion. When viewing with your local XYZ axes aligned with the global XYZ axes, you would see one instant of the scene as normal. Moving along the fourth axis, which I'll call T, will let you see the same, earlier or later in time, but if you rotate parallel to the T axis, you will effectively replace one of X, Y or Z with T. In essence you will turn the time axis into a spacial axis and the spacial axis into a time axis. Looking at a scene with space and time lumped into one 4D space might help in trying to better understand time, why it's different, and its relationship with space. I was also wondering about general relativity. I'm not going to go into too much detail, but basically: if an object with synchronized clocks on either end of it, passes by a static observer while traveling near the speed of light, to the outside observer, the object will appear shorter and the clocks will appear desynchronized, and from the object's perspective, it is the outside observer that becomes distorted this way. I was wondering if this seemingly strange effect is actually the natural consequence of a simple geometric transformation, such as rotation into the time axis. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hyper-spacial ray-tracer
On Sat, Oct 5, 2013 at 10:17 AM, Rouslan Korneychuk wrote: > The point of this was to explore the concept of hyperspace, which is a > mathematical curiosity and also has relevance in theoretical physics. I don't have any actual use-case for what you've done, but it sure sounds cool! Having worked with 3D ray-tracing (with POV-Ray), I'm slightly in awe of the possibility of going to ten dimensions... yup, cool! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Hyper-spacial ray-tracer
On 10/04/2013 09:41 PM, Chris Angelico wrote: On Sat, Oct 5, 2013 at 10:17 AM, Rouslan Korneychuk wrote: The point of this was to explore the concept of hyperspace, which is a mathematical curiosity and also has relevance in theoretical physics. I don't have any actual use-case for what you've done, but it sure sounds cool! Having worked with 3D ray-tracing (with POV-Ray), I'm slightly in awe of the possibility of going to ten dimensions... yup, cool! Thanks. For a while, I was worried nobody else thought it was interesting. It's funny that you say that about ten dimensions, considering I was thinking I should add scroll bars to the example script so the controls don't get cut off when going to 100 dimensions. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hyper-spacial ray-tracer
On Saturday, October 5, 2013 8:17:52 AM UTC+8, Rouslan Korneychuk wrote: > On 10/04/2013 04:23 PM, Tony the Tiger wrote: > > > On Wed, 02 Oct 2013 17:05:32 -0400, Rouslan Korneychuk wrote: > > > > > >> game > > > > > > Sorry, but that sounds awful. I hate games. > > > > > > > This... isn't a game or even related to gaming. Is it because of the use > > of Pygame that you thought it was. I use Pygame because it's a wrapper > > for SDL, which gives you cross-platform graphics, input and even thread > > support, and because the additional drawing and font modules are useful > > for prototyping and implementing user-interfaces for navigating > > higher-dimensional space. > > > > The point of this was to explore the concept of hyperspace, which is a > > mathematical curiosity and also has relevance in theoretical physics. > > > > One idea I had for this was to simulate some sort of 3D scene involving > > physics (probably in another program, such as Blender), take the > > resulting coordinates of the geometry at every time interval and plot it > > as one 4D static scene. Every pair of connected vertexes would be > > extruded from one instant in time, to the next, so each object is a > > continuous 4D extrusion. When viewing with your local XYZ axes aligned > > with the global XYZ axes, you would see one instant of the scene as > > normal. Moving along the fourth axis, which I'll call T, will let you > > see the same, earlier or later in time, but if you rotate parallel to > > the T axis, you will effectively replace one of X, Y or Z with T. In > > essence you will turn the time axis into a spacial axis and the spacial > > axis into a time axis. > > > > Looking at a scene with space and time lumped into one 4D space might > > help in trying to better understand time, why it's different, and its > > relationship with space. > > > > I was also wondering about general relativity. I'm not going to go into > > too much detail, but basically: if an object with synchronized clocks on > > either end of it, passes by a static observer while traveling near the > > speed of light, to the outside observer, the object will appear shorter > > and the clocks will appear desynchronized, and from the object's > > perspective, it is the outside observer that becomes distorted this way. > > I was wondering if this seemingly strange effect is actually the natural > > consequence of a simple geometric transformation, such as rotation into > > the time axis. Use the synchronous digital logics with a globbal clock by iterators of various actions for this kind of projects in Python. Please check myHDL and Python. auto- -- https://mail.python.org/mailman/listinfo/python-list
