Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 10:53, schrieb Νικόλαος Κούρας: I ALSO HAVE GIVEN ROOT ACCESS TO ANOTHER MEMBER OF THIS LIST AND HE IN FACT TRIED TO HELP ME INSTEAD OF DOING WHAT YOU DID. AND FROM 2 OTHER PEOPLE AS SOME OTHER FORUMS TOO. You know what you're saying there? You've given (at least) four people you don't know at all (you know, on the internet nobody knows you're a dog and stuff) - and as such shouldn't trust them at all, either - free and full admission to a system that critical for you. That's like handing out keys to the front door of your home to any passer-by on the street who you feel like talking to - and then later wondering why your belongings are suddenly gone. Seeing how riled up you get about this, what Chris did is for the better. At least it seems that you won't be able to change your root password back, either, and as such you won't have root access anymore to your system for the time being, which makes your system and the internets a safer place for now. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 11:19, schrieb Chris Angelico: Not quite accurate; he can change his root password back as soon as he logs in as the non-root user and cats one little file. I understood that - I rather got the impression that he (as a person) wasn't technically capable of changing it. Alas, the internets didn't remain a better place for long. :-) -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 11:33, schrieb Νικόλαος Κούρας: It will remain, if you go away. Look, pal, I work as a programmer for a (medium size) network service provider, and due to that I (should) know my networking security 101. It's generally people like you who are: 1) extremely careless about their system 2) intolerably naive and persistently refusing to learn and who as a consequence hand out root logins for hosts with big (!) pipes to people that should - under no circumstances ever, EVER - be trusted, who are in turn causing the scourge of the public internets that's called a botnet. It doesn't matter whether you're simply so stupid (yes, I said it!) as to hand out actual root logins or whether you refuse to update your system or whether you use weak passwords: in all cases, your system is compromised, and due to the rather big pipe that your system has it in turn compromises the integrity of the whole network that the system is connected to. Chris is completely right: you shouldn't thank him for not doing 'rm -rf /' on your system (that's utter peanuts, and only hits you), you should rather thank him for not copying your complete client data (and in turn their client's data, let's talk about identity theft) and/or for not installing a bot on your system which would in turn cause me to have headaches when the bot's misused to DDoS or for any other form of network-based attack on the network that I need to administer. It's you who's the untrustworthy, completely unreliable and utterly irresponsible member of the community of networks that's called the Internet. Please go somewhere else. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 12:21, schrieb Νικόλαος Κούρας: I dont care what you do for a living, you never helped me a bit in anything, you just presented to me your self 1 hour ago to join the party. Guess why I did so: you're presently touching a subject (network safety) that I hold dear, and not only being a troll. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 12:30, schrieb Νικόλαος Κούρας: You and Heiko of course would be excluded from the programmer for hire list. Guess what: I have a job. And I don't give a damn. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 13:07, schrieb Νικόλαος Κούρας: Btw, since history doesnt show me his history comamnds when he logged in from .au(why not really?), how can i tell what exactly did he do when he logged on to the server? As root has full access to your system (i.e., can change file contents and system state at will), and you gave him root access: you can't. And he made sure to remove things such as .bash_history and the syslog contents, I guess. At least that's what I'd have done to prove a point. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Am 05.06.2013 13:19, schrieb Νικόλαος Κούρας: Is there some logging utility i can use next time iam offering root access to someone(if i do it) or perhaps logging a normal's account activity? Short answer: Not for root, no. Long answer: as I've already said: root can change file contents, or more explicitly _any_ system state, and (s)he can do that at will, and as such you can't ever be sure that what any form of logging is telling you will be the "truth" in some form or another if you've had a malicious root user on your system. Now: think again why it's such a plain stupid and incredibly bad idea to hand out root credentials to people you shouldn't trust, and why people (like me) keep telling you that you're naive and a fool to even consider handing out root logins. PS: the same is true for normal logins. You don't know whether some form of privilege escalation exists on your system, so even by handing out supposedly safe non-root accounts, your installation might get compromised due to insecure SUID software or due to privilege escalation bugs in the kernel. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
Am 05.06.2013 18:44, schrieb MRAB: From the previous posts I guessed that the filename might be encoded using ISO-8859-7: >>> s = b"\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3" >>> s.decode("iso-8859-7") 'Ευχή\\ του\\ Ιησού.mp3' Yes, that looks the same. Most probably, his terminal is set to ISO-8859-7, so that when he issues the rename command on the command-line of his shell session, the "mv" command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
Am 06.06.2013 12:35, schrieb Νικόλαος Κούρας: ni...@superhost.gr [~/www/data/apps]# ls -l | file - /dev/stdin: ASCII text Did you actually try to understand what I wrote? -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
Am 06.06.2013 13:00, schrieb Νικόλαος Κούρας: Heiko, the ssh client i used to 'mv' the .mp3 was putty.Do you mean that putty is responsible for the encoding mess? Exactly. Check the encoding that putty uses for the terminal session. If it doesn't use UTF-8, switch your terminal session to UTF-8 and try the rename again. If it does, try to use another terminal client (I recommend the Cygwin-Suite). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
Am 06.06.2013 13:24, schrieb Νικόλαος Κούρας: ni...@superhost.gr [~/www/data/apps]# ls *.mp3 | file - /dev/stdin: ASCII text Again, did you actually read (and try to understand) what I wrote? I said to redo the rename after you change your terminal session to UTF-8. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Don't feed the troll... (was: Re: A few questiosn about encoding)
Am 14.06.2013 10:37, schrieb Nick the Gr33k: So everything we see like: 16474 nikos abc123 everything is a string and nothing is a number? not even number 1? Come on now, this is _so_ obviously trolling, it's not even remotely funny anymore. Why doesn't killfiling work with the mailing list version of the python list? :-( -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
Am 14.06.2013 11:32, schrieb Nick the Gr33k: I'mm not trolling man, i just have hard time understanding why numbers acts as strings. If you can't grasp the conceptual differences between numbers and their/a representation, it's probably best if you stayed away from programming alltogether. I don't think you're actually as thick as you sound, but rather either you're simply too damn lazy to take the time to inform yourself from all the hints/links/information you've been given, or you're trolling. I'm still leaning towards the second. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the help-vampire
Am 14.06.2013 14:09, schrieb rusi: Since identifying a disease by the right name is key to finding a cure: Nikos is not trolling or spamming; he is help-vampiring. Just to explain the trolling allegation: I'm not talking about him wanting to get his scripts fixed, that's help-vampiring most certainly, and an extreme form of that (thanks btw. for pointing me to that term, whoever did). I was talking about his repeated attempts at "making conversation" by asking questions about encoding, short-circuit evaluation and such which seem like they are relevant for him to solve his problem, but due to his persistence of understanding things in a wrong way/not understanding them at all/repeating the same misunderstandings time after time have drifted off into endless repetitions of the same facts by helpful posters, and have gotten a lot of people seriously annoyed (also, due to other facts such as him changing his NNTP hosts and/or From-addresses which breaks kill-filing). Now, if that latter behaviour isn't trolling, I don't know what is. Simply nobody who takes what he does at least a little bit serious is _as_ thick as he makes himself seem. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
Am 14.06.2013 14:45, schrieb Nick the Gr33k: we are all benefit out of this. Let's nominate you for a nobel prize, saviour of python-list! -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: FSR and unicode compliance - was Re: RE Module Performance
Am 29.07.2013 13:43, schrieb wxjmfa...@gmail.com: 3.2 timeit.timeit("r = dir(list)") 22.300465007102908 3.3 timeit.timeit("r = dir(list)") 27.13981129541519 For the record, I do not put your example to contradict you. I was expecting such a result even before testing. Now, if you do not understand why, you do not understand. There nothing wrong. Please give a single *proof* (not your gut feeling) that this is related to the FSR, and not rather due to other side-effects such as changes in how dir() works or (as Chris pointed out) due to more members on the list type in 3.3. If you can't or won't give that proof, there's no sense in continuing the discussion. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Perl Golf] Round 1
Am 05.02.2012 12:49, schrieb Alec Taylor: Solve this problem using as few lines of code as possible[1]. Pardon me, but where's "the problem"? If your intention is to propose "a challenge", say so, and state the associated problem clearly. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Perl Golf] Round 1
Am 05.02.2012 23:15, schrieb Neal Becker: Heiko Wundram wrote: Am 05.02.2012 12:49, schrieb Alec Taylor: Solve this problem using as few lines of code as possible[1]. Pardon me, but where's "the problem"? If your intention is to propose "a challenge", say so, and state the associated problem clearly. But this really misses the point. Python is not about coming up with some clever, cryptic, one-liner to solve some problem. It's about clear code. If you want clever, cryptic, one-liner's stick with perl. You're only allowed to bash him for one-liners as soon as he formulates something that in some way or another resembles a programming challenge, and not some incoherent listing of words without actual intent... ;-) -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to read serial stream of data [newbie]
Am 07.02.2012 14:48, schrieb Antti J Ylikoski: On 7.2.2012 14:13, Jean Dupont wrote: ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1, rtscts=0, dsrdtr=0, timeout=15) In Python, if you want to continue the source line into the next text line, you must end the line to be continued with a backslash '\'. Absolutely not true, and this is bad advice (stylistically). When (any form of) brackets are open at the end of a line, Python does not start a new command on the next line but rather continues the backeted content. So: ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1, rtscts=0, dsrdtr=0, timeout=15) is perfectly fine and certainly the recommended way of putting this. Adding the backslash-continuation is always _possible_, but only _required_ when there are no open brackets. So: x = "hello" \ " test" is equivalent to: x = ("hello" " test") in assigning: x = "hello test" -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency between os.getgroups and os.system('groups') after os.setgroups()
Am 25.03.2012 23:32, schrieb jeff: After the os.setgroups, os.getgroups says that the process is not in any groups, just as you would expect... I can suppress membership in the root group only by doing os.setgid and os.setuid before the os.system call (in which case I wind up in the group of the new user instead of root), but I have to be able to get back to root privilege so I can't use setgid and setuid. Simply not possible (i.e., you can't drop root privileges, be it by setuid()/setgid() or removing yourself from groups with setgroups()), and later reacquire them _in the same process_. See the discussion of how to implement privilege separation at http://www.citi.umich.edu/u/provos/ssh/privsep.html (which discusses how this is implemented in OpenSSH) by running multiple processes which communicate through IPC mechanisms, and each of those drops the rights it requires. Using IPC to implement reduced-privilege process spawning has a long history; also, Postfix comes to mind as an "early" adopter of a privilege separation mechanism. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: "convert" string to bytes without changing data (encoding)
Am 28.03.2012 11:43, schrieb Peter Daum: ... in my example, the variable s points to a "string", i.e. a series of bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. No; a string contains a series of codepoints from the unicode plane, representing natural language characters (at least in the simplistic view, I'm not talking about surrogates). These can be encoded to different binary storage representations, of which ascii is (a common) one. What I am looking for is a general way to just copy the raw data from a "string" object to a "byte" object without any attempt to "decode" or "encode" anything ... There is "logically" no raw data in the string, just a series of codepoints, as stated above. You'll have to specify the encoding to use to get at "raw" data, and from what I gather you're interested in the latin-1 (or iso-8859-15) encoding, as you're specifically referencing chars >= 0x80 (which hints at your mindset being in LATIN-land, so to speak). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: "convert" string to bytes without changing data (encoding)
Am 28.03.2012 19:43, schrieb Peter Daum: As it seems, this would be far easier with python 2.x. With python 3 and its strict distinction between "str" and "bytes", things gets syntactically pretty awkward and error-prone (something as innocently looking like "s=s+'/'" hidden in a rarely reached branch and a seemingly correct program will crash with a TypeError 2 years later ...) It seems that you're mixing things up wrt. the string/bytes distinction; it's not as "complicated" as it might seem. 1) Strings s = "This is a test string" s = 'This is another test string with single quotes' s = """ And this is a multiline test string. """ s = 'c' # This is also a string... all create/refer to string objects. How Python internally stores them is none of your concern (actually, that's rather complicated anyway, at least with the upcoming Python 3.3), and processing a string basically means that you'll work on the natural language characters present in the string. Python strings can store (pretty much) all characters and surrogates that unicode allows, and when the python interpreter/compiler reads strings from input (I'm talking about source files), a default encoding defines how the bytes in your input file get interpreted as unicode codepoint encodings (generally, it depends on your system locale or file header indications) to construct the internal string object you're using to access the data in the string. There is no such thing as a type for a single character; single characters are simply strings of length 1 (and so indexing also returns a [new] string object). Single/double quotes work no different. The internal encoding used by the Python interpreter is of no concern to you. 2) Bytes s = b'this is a byte-string' s = b'\x22\x33\x44' The above define bytes. Think of the bytes type as arrays of 8-bit integers, only representing a buffer which you can process as an array of fixed-width integers. Reading from stdin/a file gets you bytes, and not a string, because Python cannot automagically guess what format the input is in. Indexing the bytes type returns an integer (which is the clearest distinction between string and bytes). Being able to input "string-looking" data in source files as bytes is a debatable "feature" (IMHO; see the first example), simply because it breaks the semantic difference between the two types in the eye of the programmer looking at source. 3) Conversions To get from bytes to string, you have to decode the bytes buffer, telling Python what kind of character data is contained in the array of integers. After decoding, you'll get a string object which you can process using the standard string methods. For decoding to succeed, you have to tell Python how the natural language characters are encoded in your array of bytes: b'hello'.decode('iso-8859-15') To get from string back to bytes (you want to write the natural language character data you've processed to a file), you have to encode the data in your string buffer, which gets you an array of 8-bit integers to write to the output: 'hello'.encode('iso-8859-15') Most output methods will happily do the encoding for you, using a standard encoding, and if that happens to be ASCII, you're getting UnicodeEncodeErrors which tell you that a character in your string source is unsuited to be transmitted using the encoding you've specified. If the above doesn't make the string/bytes-distinction and usage clearer, and you have a C#-background, check out the distinction between byte[] (which the System.IO-streams get you), and how you have to use a System.Encoding-derived class to get at actual System.String objects to manipulate character data. Pythons type system wrt. character data is pretty much similar, except for missing the "single character" type (char). Anyway, back to what you wrote: how are you getting the input data? Why are "high bytes" in there which you do not know the encoding for? Generally, from what I gather, you'll decode data from some source, process it, and write it back using the same encoding which you used for decoding, which should do exactly what you want and not get you into any trouble with encodings. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write when forking a python process
Am 08.04.2011 18:14, schrieb John Connor: > Has anyone else looked into the COW problem? Are there workarounds > and/or other plans to fix it? Does the solution I am proposing sound > reasonable, or does it seem like overkill? Does anyone foresee any > problems with it? Why'd you need a "fix" like this for something that isn't broken? COW doesn't just refer to the object reference-count, but to the object itself, too. _All_ memory of the parent (and, as such, all objects, too) become unrelated to memory in the child once the fork is complete. The initial object reference-count state of the child is guaranteed to be sound for all objects (because the parent's final reference-count state was, before the process image got cloned [remember, COW is just an optimization for a complete clone, and it's up the operating-system to make sure that you don't notice different semantics from a complete copy]), and what you're proposing (opting in/out of reference counting) breaks that. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write when forking a python process
Am 08.04.2011 20:34, schrieb jac: > I disagree with your statement that COW is an optimization for a > complete clone, it is an optimization that works at the memory page > level, not at the memory image level. In other words, if I write to a > copy-on-write page, only that page is copied into my process' address > space, not the entire parent image. To the best of my knowledge by > preventing the child process from altering an object's reference count > you can prevent the object from being copied (assuming the object is > not altered explicitly of course.) As I said before: COW for "sharing" a processes forked memory is simply an implementation-detail, and an _optimization_ (and of course a sensible one at that) for fork; there is no provision in the semantics of fork that an operating system should use COW memory-pages for implementing the copying (and early UNIXes didn't do that; they explicitly copied the complete process image for the child). The only semantic that is specified for fork is that the parent and the child have independent process images, that are equivalent copies (except for some details) immediately after the fork call has returned successfully (see SUSv4). What you're thinking of (and what's generally useful in the context you're describing) is shared memory; Python supports putting objects into shared memory using e.g. POSH (which is an extension that allows you to place Python objects in shared memory, using the SysV IPC-featureset that most UNIXes implement today). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem receiving UDP broadcast packets.
Am 20.04.2011 01:54, schrieb Grant Edwards: > I guess the problem is that I expected to receive a packet on an > interface anytime a packet was received with a destination IP address > that matched that of the the interface. Apprently there's some > filtering in the network stack based on the _source_ address as well > (that seems very counter-intuitive to me). Just to pitch in here (because nobody's mentioned it yet AFAICT): yes, there's a filtering done (at least under Linux, and I'd guess something similar on xBSD too) to packets based on the source address coming in on an interface, and it's called the reverse path filter and is on by default (the tunable on Linux is /proc/sys/net/ipv4/conf/*/rp_filter). The idea behind the reverse path filter is that your machine won't accept packets coming in over an interface when a return packet (i.e., the presumed response) won't be routed over the same interface, and from what I gather, this is what makes the TCP/IP stack drop the packets because your machine will not route packets to 192.168.x.x over the same interface it sees the packet coming in. This is a _security_ feature, because it makes address spoofing harder. If you need to see the packets regardless, either use a promiscuous mode sniffer (i.e., tcpdump, but that's relatively easy to mirror in Python using SOCK_RAW, capturing packets at the ethernet level), or add a route on your system for the 192.168.x.x network on the same interface. HTH! -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem receiving UDP broadcast packets.
Am 20.04.2011 16:30, schrieb Grant Edwards: >> If you need to see the packets regardless, either use a promiscuous mode >> sniffer (i.e., tcpdump, but that's relatively easy to mirror in Python >> using SOCK_RAW, capturing packets at the ethernet level), or add a route >> on your system for the 192.168.x.x network on the same interface. > > I've thought about the SOCK_RAW option, but the CPU load of looking > all received Ethernet packets in user-space would be a big down-side. Not necessarily: instead of using UDP datagrams to send the data, use ethernet datagrams (without any IP/UDP header) with your own ethernet-type (there is a range of "local" types that you can use for your own local use-case), and then simply create a RAW socket that only listens on packets that have the specified ethernet types. We use something similar at work for a high-availability application. The server-side looks something like: """ PKT_TYPE = 0x1234 # My very own ethertype. sock = socket(AF_PACKET,SOCK_DGRAM,htons(PKT_TYPE)) sock.bind(("ethxyz",PKT_TYPE)) while True: data, (_, _, _, _, addr) = sock.recvfrom(1500) print "I got:", repr(data), "from etheraddr:", addr """ The client-side looks similar. Because you're using UDP broacast, you have unreliable transport anyway, and if the client-side supports sending ethernet datagrams (with a broadcast address), I'd rather advise to use that for your use case. This makes you independent of IP configuration (and as I can see, you're actually not interested in the "routing" that IP gives you, but rather interested in contacting all nodes on a local ethernet; why not use ethernet directly?). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem receiving UDP broadcast packets.
Am 21.04.2011 03:35, schrieb Dan Stromberg: > I think tcpdump and tshark (was tethereal) will put the interface into > promiscuous mode so it can see more traffic; on OSF/1 (Tru64), we had > to do this manually for said programs to see all that was possible > (barring the presence of a switch not repeating packets the way > routers and hubs would). It actually depends on the network adapter/card that's in use: many modern cards (especially those in the lower price segment, i.e. Realtek) don't (properly) implement "MAC"-filtering at the hardware level, and in this case, there's no difference for the operating system between promiscuous mode and non-promiscuous mode (because the card will forward all packets that it sees coming in over the ethernet bus to the operating system, which will then discard those at the ethernet level it doesn't deem necessary to process at a higher level, for example because the destination MAC is unicast, but not the cards own, so the destination wasn't the system itself). For pricier cards/chips, this filtering (which also includes restricting the multicast-destinations that are forwarded to the operating system, think IPv6-multicast which uses quite a range of multicast MAC addresses for its neighbour discovery) is implemented at the hardware level, and the ethernet adapter throws away uninteresting packets and doesn't signal the operating system (think of the cost of interrupts you save; on high throughput links, this makes perfect sense). Putting the card into promiscuous mode basically disables this filtering, so that the card will again forward all packets to the operating system. This is why tcpdump for example puts the network adapter into promiscuous mode, but normally (see above, depending on the network adapter), that's not required because the operating system "sees all" ethernet packets anyway. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: learnpython.org - an online interactive Python tutorial
Am 21.04.2011 09:19, schrieb Chris Angelico: > On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila wrote: >> False: Python IS strongly typed, without doubt (though the >> variables are not explicitly declared.) > > Strongly duck-typed though. If I create a class that has all the right > members, it can simultaneously be a file, an iterable, a database, and > probably even a web browser if it feels like it. Is that strong typing > or not? Yes, that's strong typing, because your class only works in those contexts that you "explicitly" allow it to work in (through implementing an interface, be it an iterator, a file, etc.), independent of "duck-typing" (which is pretty much described by the term interface-based typing IMHO). The difference between strong typing and weak typing is best described by: Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) [GCC 4.3.4 20090804 (release) 1] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> 1+'2' Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> which means that the interface for implementing "+" on the input types "int" and "str" isn't implemented (i.e., TypeError). Weakly typed languages allow this to work: modelnine@gj-celle ~ $ php 3 modelnine@gj-celle ~ $ through all kinds of type-casting magic, which isn't explicitly specified as interfaces on the objects (PHP also has integer and string objects) themselves. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a difference between one line and many lines
Am 21.04.2011 11:55, schrieb vino19: > I am asking about what happens in Python interpreter? Why is there a > difference between running one line like "a=1;b=1" and two lines like "a=1 \n > b=1"? Does it decide to locate memory in different types depend on a code? There is no difference between the two. You've not given the initializers for a/b in the two statement groups you showed, so that what Chris Angelico said is probably what's happening here (i.e.: in the first case, you stay in the singleton range, in the second case which builds on the first, you don't). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a difference between one line and many lines
Am 21.04.2011 11:59, schrieb Heiko Wundram: > Am 21.04.2011 11:55, schrieb vino19: >> I am asking about what happens in Python interpreter? Why is there a >> difference between running one line like "a=1;b=1" and two lines like "a=1 >> \n b=1"? Does it decide to locate memory in different types depend on a code? > > There is no difference between the two. > ... Erm, sorry, forget my post. I misread a=-6 as a-=6, etc... So: what Chris said. Anyway, there is semantically no difference between the two, and that stands. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
PyAuthD - beta 6
Hi all! It's been a while since I've announced a version of PyAuthD, and we're nearing a 0.1 release steadily. Beta 6 marks a milestone as the current release has been powering the backend of our virtual mail and VPN solution for about three months now. But, now, for release info: What is PyAuthD? PyAuthD is an authentication and mail framework for Unix(-like) systems. It offers a uniform backend interface in the form of a Python daemon for easy integration of PAM, NSS, Postfix Maps, pppd and Squirrelmail into a user-specified authentication framework. A twisted-cred interface to PyAuthD is in the works. It's currently in use for offering a virtual mail and VPN solution for students of the Medizinische Hochschule Hannover, Germany, on a Linux server. It interfaces fine with poptop, Postfix, glibc and PAM to authenticate and manage mail-accounts for our users. For completely secure operation (where users have login-rights to the vmail host), PyAuthD requires a Python with my patches for the socket module to expose some Linux-only functionality with regards to Unix-Domain-Sockets. These patches have been posted to the Python bug repository, but I'm currently unable to push them to be included in the main tree, so please go and see http://svn.asta.mh-hannover.de/asta/Python/trunk for my currently deployed Python version (there's an ebuild for Gentoo to check out available). What is PyAuthD not? - An out of the box virtual mail solution. That's why we're not at a version 0.1 yet, as the code needs to be (somewhat) refactored to be more widely deployable. There are two source files which are specific for our installation (the backend, actually), and basically these would have to be reworked for a remote site wanting to use this. - A complete implementation of the relevant interfaces. All the interface elements which are not required for normal operation on our server (esp. PAM and NSS methods) are stubs at the moment. This will also be the subject of the 0.1 release. What license is PyAuthD distributed under? == A BSD-style license, so basically as long as you give me and the Medizinische Hochschule Hannover credit for writing it you're free to do with it whatever you please. Read LICENSE in the project root for more details. Where can I get it? === Currently, there's no distribution file yet. You'll have to use our subversion repository: http://svn.asta.mh-hannover.de/asta/PyAuthD/trunk for the project trunk and http://svn.asta.mh-hannover.de/asta/PyAuthD/tags/beta-6 for the currently tagged version. The trunk might not contain functioning code, but most of the time will. Where can I get more dev info on PyAuthD? = Read the (german) blog at: http://svn.asta.mh-hannover.de/categories/python/pyauthd/ Mailinglists and bugtrackers Go to: http://lists.stud.mh-hannover.de/mailman/listinfo/pyauthd and http://mantis.stud.mh-hannover.de and subscribe to the list and the bugtracker. All the rest... === If you require more info or want to join the development effort, just send me a mail or join the mailinglist. --- Heiko Wundram Student Network Administrator, Medical University of Hannover, Germany -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic variable referencing
Michael Williams wrote: > - I don't want to say OBJECT.VAR but rather OBJECT. > ("string") and have it retrieve the variable (not the value of > it) if in fact it exists. . . > > > It's not exactly clear what you're trying to tell us here. Basically, what I guess you want is: getattr(object,"varname") This retrieves the value that is bound to varname at "namespace" object. You cannot retrieve a variable per se in Python, as a variable is just a name that is a binding to an object. The second part of what you're trying to do sounds more like stacking objects. I'll just give it a shot and implement a little bit to test on. You'll have to extend it to suit your needs... ;-) class xmlnode(object): def __init__(self): self.__subnodes = {} self.__value = "" def __getattr__(self,item): if item == "value": return self.__value elif item.startswith("_"): raise AttributeError, item elif item not in self.__subnodes: self.__subnodes[item] = xmlnode() return self.__subnodes[item] def __setattr__(self,item,value): if item.startswith("_"): super(xmlnode,self).__setattr__(item,value) elif item == "value": assert isinstance(value,(str,unicode)) self.__value = value else: assert isinstance(value,(str,unicode)) if item not in self.__subnodes: self.__subnodes[item] = xmlnode() self.__subnodes[item].value = value def __delattr__(self,item): if item.startswith("_"): super(xmlnode,self).__delattr__(item) elif item == "value": self.__value = None else: try: del self.__subnodes[item] except KeyError: raise AttributeError, item def toXML(self,name): rv = ["<%s>" % name] for sname, sitem in self.__subnodes.iteritems(): rv.append(sitem.toXML(sname)) if self.__value is not None: rv.append(self.__value) rv.append("" % name) return "".join(rv) This implements a simple XML-tree builder with a very specific output format (tags contain only one string value, which always comes after any subtag that they might contain, and subtag order is random). The "tricky" part is in the __*attr__ logic to get subnodes. Example of usage: >>> a = test.xmlnode() >>> a >>> a.value = "test" >>> a.toXML("root") 'test' >>> a.book = "welcome" >>> a.anotherbook = "bye" >>> a.toXML("root") 'byewelcometest' >>> a.book.value 'welcome' >>> a.book.anotherbook.somethingelse.thisislong = "test" >>> a.toXML("root") 'byetestwelcometest' >>> HTH! --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: JPEG decoder not available in PIL
Peter wrote: > At the last moment I managed to solve this problem and I hope it is > worth supplying the details here. First there is a file in the install > directory libImaging/Jpeg.h which has a line: > > #include "jpeglib.h" > > but there is no such header file. On my system I put: > > #include "/usr/local/include/jpeglib.h" > > which is where the JPEG installation put the include files for the > library. With this change all 55 tests passed successfully. This is bad! You're mixing two libraries here, for one the system jpeg library and for another your library. Probably the dynamic loader cache finds the system library first, so although you included the specifications for the library you installed to /usr/local, you link against the system library which might be different (in this case it is not and for jpeglib will never be, but nevertheless, this is an absolute NONO). PIL comes precompiled for SuSE, btw., and the package is called Imaging, IIRC (long time since I've tried SuSE). Next time round you want to install something, read up on the distinction between and -devel. The former contains only the files necessary at runtime (thus, no static libraries, no headers, etc.), while the latter contains everything the package installs that isn't in the former. Thus, to install PIL you should have done: rpm -Uvv libjpeg-devel-.rpm or installed libjpeg-devel using the SuSE package manager. Then the PIL intallation would have found the appropriate header files and compiled successfully. Actually, you must have installed python-devel for the installation package to succeed. Or did you build Python yourself and overwrote the standard python that was installed? If so, really do read up on package management using RPM, there's quite a lot on this on SuSE's site. Otherwise you'll wreck your system in the longrun... --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: can't find socket.ssl() on win32
ds wrote: > i'm running under win2k trying to implement an ssl socket, and keep > getting the error > File "C:\Code\Python\ssl\NewsSrc.py", line 67, in connect > ssl = socket.ssl(sock, None, None) > AttributeError: 'module' object has no attribute 'ssl' > i'm running this under ActiveState version 2.2.2, but i have also tried > under ActiveState version 2.3 anyone have any ideas? IIRC socket.ssl wasn't available under Windows (because of it relying on the OpenSSL libraries), but I can't seem to find any reference to documentation at the moment... You can always use m2crypto which implements SSL sockets under Unix and under Windows. http://sandbox.rulemaker.net/ngps/m2/ HTH! --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: List index question
questions? wrote: > I want to do list index function. y=['1','2','3','4'] y > ['1', '2', '3', '4'] y.index['2'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unsubscriptable object > > It works with y=[1,2,3,4]. Anyone has any hint, what's the reason > here? You're mixing things up badly. Either you want to call the function .index() of the list object, in which case you don't use angle brackets but rather round brackets (which works): >>> y = ['1','2','3','4'] >>> y.index('2') 1 or you want to get an element at a specified position in the list, in which case you don't use .index() but rather index the object using []: >>> y = ['1','2','3','4'] >>> y[2] '3' What you're trying to do is use a string as an index, which is bound to fail: >>> y['2'] Traceback (most recent call last): File "", line 1, in ? TypeError: list indices must be integers And the error message says it all: a list index must be an integer. I guess you better do some reading up on Python syntax... Have you done the tutorial? --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: opening a file using a relative path from a subclass in a package
spike grobstein wrote: > I'd like the packages to define a file path for supporting files > (graphics, etc) that are stored inside the package. The problem is that > the superclass's definition (stored elsewhere) has all of the code for > actually opening the files, so when I use the > os.path.dirname(os.path.abspath(__file__)) trick, it's finding the > superclass, not the package's path. Try: import sys os.path.dirname(os.path.abspath(sys.modules[self.__class__.__module__].__file__)) if you have an instance object (self) at hand, otherwise os.path.dirname(os.path.abspath(sys.modules[selfcls.__module__].__file__)) if you have a class object (selfcls) at hand. Thing being why your approach doesn't work is that __file__ references a global which is always resolved in the namespace the function is defined in, so the source file it's defined in. You can get at the module object (the global namespace) of a class object by using the sys.modules trick. Be aware that this is pretty... non-standard stuff, to say it mildly... ;-) HTH! --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: opening a file using a relative path from a subclass in a package
spike grobstein wrote: > so, since python supports module packages like it does, you'd think > that it would have ways of making add-on or extension modules to be > more self contained. Errm... You're not quite understanding what the problem is about. A class is just an object. A class object may appear in many modules (namespaces), even in non-module namespaces (function namespaces). It's part of the debugging system that a class is bound to a module (by the __module__ member of the class object), which helps in finding the source for a class if you're the debugger. The method I wrote to you won't work if you import the class from some file and want to get the file where the class is imported, not where it's defined. So, the following won't do what you think: a.py import c class x: __metaclass__ = c.superclass pass b.py from a import x c.py class superclass(type): def __init__(cls,name,bases,dct): print cls.__module__ d.py import b python d.py will print "a" and not "b" what you might have expected. So, actually this is quite fragile stuff, and is something that's better left alone if you care for portable code. Why do you desperately need access to the source file of the extension class? Isn't it enough that you import the extension class and rely on the fact that its module object has a member which is a class object which defines a certain interface? Can't you use the class name if you need a unique identifier for the class in your system? (self.__class__.__name__) Think about it... --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: calculate system disk space
PyPK wrote: > I am looking for unix.the recipe is windows specific!! Parse the output of du/df? :-) I guess that would be simplest... ;-) Otherwise, use some combination of os.walk() and os.stat(), whereby you _don't_ use the stat.st_size field to get the file size (on disk) but rather use stat.st_blocks*stat.st_blksize to get it, as you might come across so called sparse files which are bigger than their on-disk representation. For explanations, see: http://www.python.org/doc/2.4.2/lib/os-file-dir.html (entries for stat() and walk()) --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Properties transfer between instances of different classes, without subclassing
Pierre wrote: > Ideally, 'tabv.cold' would give me 'tabv', masked where the values are > <10. > I don't want to make 'Tabl' a subclass of 'Temp'. I'd like to use it > more generically, so that when I define a 3rd class 'Color', I could > initiate 'Tabv' with an instance of 'Color', accessing the 'Color' > properties without the 'Temp' properties. I guess interfaces could make your day: http://www.zope.org/Products/ZopeInterface --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help
Am Dienstag, 1. März 2005 21:53 schrieb brian: > They tell me the error is Recv Timed Out. This sounds like a socket level (TCP/IP stack) error, which might be caused by a malfunctioning gateway or network device (likely), an error in the operating system or network device driver they use (unlikely), or a combination of several malfunctions. But, this certainly isn't an error that's Python related (IMHO), so you better tell them to check their hardware... -- --- Heiko. pgp8j11DaRYRp.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Communication between python scripts
Am Dienstag, 1. März 2005 21:54 schrieb Chris: > Is there a preferred method for having different scripts on different > computers communicate with each other? You have several options at your disposal. 1) Use mail-communication (like you said, a combination of smtplib and poplib/imaplib), 2) have the scripts update web-pages which can be accessed by the other script to read status information (a combination of ftplib and urllib2), 3) write a socket server process running on some computer which can be connected by both clients to update certain flags which can then be read by the other process (see SimpleXMLRPCServer), 4) write both programs so that they spawn an additional thread which runs a socket server (e.g. SimpleXMLRPCServer) which can be used to query their state from the other process, 5) use some RPC-package like Pyro (http://pyro.sourceforge.net/), Twisted+Banana (http://www.twistedmatrix.com/), CORBA, etc. 6) do something else which doesn't come to my mind just now. ;) You have many options at your disposal, and which of the above options you choose will depend largely on what your prerequesites are, such as: 1) Do both machines reside on the same network, or do they need gateways to communicate (like a mail server in option 1)? 2) Are you willing to install packages like Pyro which do not belong to the stdlib on both computers? 3) Can you run some server process on a machine which is reachable by both processes? 4) And anything else which I didn't think of just now... ;) I'd say, if you aren't constrained in some form, go for Pyro to start with. Nice and simple. -- --- Heiko. pgpJyI4QBv0U9.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Help- Simple recursive function to build a list - Sorry for all the noise!
On Wednesday 02 March 2005 06:03, actuary77 wrote: > It now makes sense if I write it, (simple): > > def rec2(n): > if n == 0: > return [] > else: > return [n] + rec2(n-1) Or, if you're not interested in a recursive function to do this job (which should be way faster...): >>> def iter1(n): ... nl = range(1,n+1) ... nl.reverse() ... return nl ... >>> print iter1(4) [4, 3, 2, 1] -- --- Heiko. pgpUjFecUi9hu.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Using for... for multiple lists
On Sunday 06 March 2005 13:09, Harlin Seritt wrote: > for i, f in filelist, self.checkbox: >if f.get(): > print i Use: for i, f in zip(filelist,self.checkbox): -- --- Heiko. pgpuQ4Xv4IUj6.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible to import a module whose name is contained in a variable?
On Monday 07 March 2005 11:52, Claudio Grondi wrote: > I try to avoid using any of the > ____() functions if possible > (considering this a good > programming style). This is never good style, at least in the case of exec. exec is evil. What works (beware that the below code is nevertheless untested and might contain little warts) and is the "usual" and clean way to go: ### libinfo/__init__.py # Empty. ### libinfo/Module1.py def libinfo(): return "I am module1." CFLAGS = ["-DMODULE1"] ### libinfo/Module2.py def libinfo(): return "I am module2." CFLAGS = ["-DMODULE2"] ### Importer.py modules = {} CFLAGS = [] def load_modules(to_load=["module1","module2"]): global modules, CFLAGS for mod in to_load: try: modules[mod] = getattr(__import__("libinfo.%s" % mod),mod) except ImportError: print "Could not load %s." % mod continue print "Module: %s (%r)." % (mod,modules[mod]) print "Modules libinfo: %r." % modules[mod].libinfo() CFLAGS += modules[mod].CFLAGS print "Total CFLAGS: %s." % CFLAGS if __name__ == "__main__": load_modules() print "Module container: %s." % modules ### End Importer.py HTH! -- --- Heiko. pgpfjzzhE3U5B.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: GOTO (was Re: Appeal for python developers)
On Sunday 06 March 2005 14:26, Anthra Norell wrote: > Wow, I never thought I'd say this, but this certainly is an ingenious use of goto... But, nevertheless, I don't think this is applicable to Python as a way of justifying goto in the language, as your program doesn't have a split between abstract state machine and real program anymore (which I think should be there, as the abstract state machine is actually data, which controls program flow). The way I'd code it in Python is something like: SETUP = object() ELSE = object() BREAK = object() machine = {"WAITING FOR ACTION": {customer_drops_coin:"COIN HAS BEEN DROPPED", customer_selects_beverage:"ORDER RECEIVED", customer_cancels_order:"ACCOUNT CLOSURE IS DUE" ELSE:"WAITING FOR ACTION"}, "COIN HAS BEEN DROPPED": {SETUP:identify_coin, credit_account:"PAYMENT DUE IS UNKNOWN"}, "ORDER RECEIVED": {... Reading the state machine in the way presented above isn't any harder in my taste than reading your state table, and you should easily be able to run the machine from there... -- --- Heiko. pgpFSqfb8wW7l.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: re - Question about pyFMOD importing
On Tuesday 08 March 2005 12:38, lior botzer wrote: > Were you able to hack this one ? I haven't seen this error in a long time (as I'm no Windows user for a long time), but from what I gather the only thing that the specified error was telling you is the fact that the dynamic linking library that ctypes wanted to load wasn't there. I guess that the library that ctypes looks for is the DLL required for FMOD (in the original example). So, basically, what I can tell you: to remedy this error, put the required DLL (whose name you can find in the sources) somewhere on the search path, so that it can be loaded by the C-call LoadLibrary(), which ctypes just conveniently wraps. The library search path should include the current path (along with %WINDIR%/system and %WINDIR%/system32), so putting the DLL there should work too. -- --- Heiko. pgpeyJhCNG6uT.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system()
On Monday 07 March 2005 14:10, Diez B. Roggisch wrote: > Showing us what commands actually fail would certainly help. Actually, this sounds like the subshell isn't getting an alias that the normal interactive shell has. Maybe because ~/.bashrc isn't read on os.system(), or something of the like? This depends largely on your default system settings, and especially on /etc/profile. You might check whether the command that works in the interactive shell is an alias by typing [EMAIL PROTECTED] ~ $ alias alias ls='ls --color=auto' [EMAIL PROTECTED] ~ $ This shows all currently set aliases, and at least on Gentoo, the above alias is set in ~/.bashrc, and thus isn't set when os.system() is called. This means that the output from running ls in an interactive shell is colorized, whereas running os.system("ls") from Python is not colorized, although TERM="xterm" in os.environ, and thusly in the subshell spawned using os.system, and ls could colorize the output using VT100 escape sequences. All the above explanations assume that your default shell /bin/sh is the Bourne Again Shell, but all other "higher shells" such as the (T)C-Shell and the Korn-Shell support command aliasing too, in some way or another, and will suffer from the same quirks. And, btw., it'll help if you read the commented start-up files (at least on Gentoo and SuSE (IIRC) they are very well commented) and the bash man-page, they explain pretty clearly which initialization files (~/.bashrc, ~/.bash_profile, /etc/profile, /etc/bash/bashrc, and several others) get executed when and where, depending on whether a shell is a login shell (your normal interactive shell), or not (spawned by os.system, for example). Hope this explanation helps! -- --- Heiko. pgpEIm4nKNAgd.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system()
On Monday 07 March 2005 14:24, Joerg Schuster wrote: > Well, I can give you the string, but that will not help: > > transduce abc info_dic comp_dic input_file output_file Several variables like PATH "normally" get reset even when running a non-login subshell to the standard values from /etc/profile (on Gentoo /etc/env.d/*), so I guess that you're just having a problem finding the executable for transduce if that program isn't installed in a path which is always on $PATH. At least I know this behaviour from some older versions of SuSE; Gentoo with bash 3.0-r8 and baselayout 1.11.9-r1 does as I would presume and doesn't reset it (there goes my example). What you might try: export PATH="/does/not/exist:$PATH" echo $PATH --- Path here --- python >>> import os >>> os.system("echo $PATH") --- Path here, different? --- and check whether they are any different. You could also do this for other important variables, such as LD_LIBRARY_PATH. But, all of this is stabbing in the dark, maybe you can just send the actual error message along next time. HTH! -- --- Heiko. pgpBcN9CKzqop.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffle the lines of a large file
On Monday 07 March 2005 14:36, Joerg Schuster wrote: > Any ideas? The following program should do the trick (filenames are hardcoded, look at top of file): ### shuffle.py import random import shelve # Open external files needed for data storage. lines = open("test.dat","r") lineindex = shelve.open("test.idx") newlines = open("test.new.dat","w") # Create an index of all lines of the file in an external flat file DB. # This means that nothing actually remains in memory, but in an extremely # efficient (g)dbm flatfile DB. def makeIdx(): i = 0L lastpos = 0L curpos = None while lines.readline(): # This is after the (\r)\n, which will be stripped() and rewritten # by writeNewLines(). curpos = long(lines.tell()) lineindex[hex(i)[2:-1]] = "%s:%s" % (hex(lastpos)[2:-1], hex(curpos-lastpos)[2:-1]) lastpos = curpos i += 1 return i maxidx = makeIdx() # To shuffle the file, just shuffle the index. Problem being: there is no # random number generator which even remotely has the possibility of yielding # all possible permutations. Thus, for simplicity: just exchange every element # in order 1..end with a random element from the rest of the file. This is # certainly no perfect shuffle, and in case the shuffling is too bad, just # rerun shuffleIdx() a couple of times. def shuffleIdx(): oldi = 0L # Use a while loop, as xrange doesn't work with longs. while oldi < maxidx: oi = hex(oldi)[2:-1] while True: ni = hex(long(random.randrange(maxidx)))[2:-1] if ni <> oi: break lineindex[oi], lineindex[ni] = lineindex[ni], lineindex[oi] oldi += 1 shuffleIdx() # Write out the shuffled file. Do this by just walking the index 0..end. def writeNewLines(): i = 0L # Use a while loop, as xrange doesn't work with longs. while i < maxidx: # Extract line index and line length from the index file. lidx, llen = [long(x,16) for x in lineindex[hex(i)[2:-1]].split(":")] lines.seek(lidx) line = lines.read(llen).strip() newlines.write(line+"\n") i += 1 writeNewLines() ### End shuffle.py I don't know how fast this program will run, but at least, it does as told... ;) -- --- Heiko. pgpeVbq0wufOV.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffle the lines of a large file
Replying to oneself is bad, but although the program works, I never intended to use a shelve to store the data. Better to use anydbm. So, just replace: import shelve by import anydbm and lineindex = shelve.open("test.idx") by lineindex = anydbm.open("test.idx","c") Keep the rest as is. -- --- Heiko. pgpbEE81rHUyx.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: determine directories with wildcard
On Tuesday 08 March 2005 14:33, Thomas Rademacher wrote: > How can I resolve this problem? python >>> import glob >>> help(glob) or look at the online documentation for glob. -- --- Heiko. pgp6MyvJSQxu3.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Split text file into words
On Tuesday 08 March 2005 14:43, qwweeeit wrote: > The standard split() can use only one delimiter. To split a text file > into words you need multiple delimiters like blank, punctuation, math > signs (+-*/), parenteses and so on. > > I didn't succeeded in using re.split()... Then try again... ;) No, seriously, re.split() can do what you want. Just think about what are word delimiters. Say, you want to split on all whitespace, and ",", ".", and "?", then you'd use something like: [EMAIL PROTECTED] ~ $ python Python 2.3.5 (#1, Feb 27 2005, 22:40:59) [GCC 3.4.3 20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0, pie-8.7 on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> teststr = "Hello qwweeeit, how are you? I am fine, today, actually." >>> re.split(r"[\s\.,\?]+",teststr) ['Hello', 'qwweeeit', 'how', 'are', 'you', 'I', 'am', 'fine', 'today', 'actually', ''] Extending with other word separators shouldn't be hard... Just have a look at http://docs.python.org/lib/re-syntax.html HTH! -- --- Heiko. pgpiHbI7zcTjy.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffle the lines of a large file
On Tuesday 08 March 2005 15:28, Simon Brunning wrote: > This has the advantage that every line had the same chance of being > picked regardless of its length. There is the chance that it'll pick > the same line more than once, though. Problem being: if the file the OP is talking about really is 80GB in size, and you consider a sentence to have 80 bytes on average (it's likely to have less than that), that makes 10^9 sentences in the file. Now, multiply that with the memory overhead of storing a list of 10^9 None(s), and reconsider, whether that algorithm really works for the posted conditions. I don't think that any machine I have access to even has near enough memory just to store this list... ;) -- --- Heiko. pgpp8eZ4iUwn7.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffle the lines of a large file
On Tuesday 08 March 2005 15:55, Simon Brunning wrote: > Ah, but that's the clever bit; it *doesn't* store the whole list - > only the selected lines. But that means that it'll only read several lines from the file, never do a shuffle of the whole file content... When you'd want to shuffle the file content, you'd have to set lines=1 and throw away repeating lines in subsequent runs, or you'd have to set lines higher, and deal with the resulting lines too in some way (throw away repeating ones... :-). Doesn't matter how, you'd have to store which lines you've already read (selected_lines). And in any case you'd need a line cache of 10^9 entries for this amount of data... That's just what I wanted to say... -- --- Heiko. pgpTTdk42z5Yz.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie:unique problem
On Thursday 17 March 2005 20:08, Leeds, Mark wrote: > But, I also want it to get rid of the AAA KP because > there are two AAA's even though the last two letters > are different. It doesn't matter to me which one > is gotten rid of but I don't know how to change > the function to handle this ? I have a feeling > it's not that hard though ? Thanks. Doing the same thing Brian van den Brook did with sets (also for 2.4 only): def uniqueItems(oldlist,comppos=3): rv = {} for i in reversed(oldlist): rv[i[:comppos]] = i return rv.values() >>> uniqueItems(["AAA BC","BBB KK","CCC TD","AAA KP","CCC TD"]) ['AAA BC', 'BBB KK', 'CCC TD'] [EMAIL PROTECTED] ~ $ python2.4 /usr/local/lib/python2.4/timeit.py -s "import test; uniqueItems = test.uniqueItems; uniqueItemsBrian = test.uniqueItemsBrian" "uniqueItemsBrian(uniqueItems)" 10 loops, best of 3: 13.8 usec per loop [EMAIL PROTECTED] ~ $ python2.4 /usr/local/lib/python2.4/timeit.py -s "import test; uniqueItems = test.uniqueItems; uniqueItemsHeiko = test.uniqueItemsHeiko" "uniqueItemsHeiko(uniqueItems)" 10 loops, best of 3: 9.28 usec per loop Seems like the dictionary solution is faster, at least for n=3. Do your own tests... ;) -- --- Heiko. pgp7Ajb86UhaT.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie:unique problem
On Thursday 17 March 2005 23:31, Brian van den Broek wrote: > Am I not > right in thinking that with the dict approach there is no guarantee > that the order from the original list will be preserved? Yup, absolutely right that the original ordering will not be preserved. But, I wonder whether this actually matters, when the op is actually using these strings as a sort of set (to check whether someone belongs to some group, if I understand him correctly). > Also, Heiko, I wonder what is the reason for reversed(oldlist)? Since > the list isn't being mutated, there isn't any danger in forward > iteration over it. (Plus, unless I'm mistaken, its the only thing > making yours a 2.4-only solution.) The reason for walking the list backwards is easily demonstrated by the following two runs: >>> def uniqueItems(oldlist,comppos=3): ... rv = {} ... for i in reversed(oldlist): ... rv[i[:comppos]] = i ... return rv.values() ... >>> def uniqueItemsWithoutRev(oldlist,comppos=3): ... rv = {} ... for i in oldlist: ... rv[i[:comppos]] = i ... return rv.values() ... >>> uniqueItems(["AAA BC","BBB KK","CCC TD","AAA KP","CCC TD"]) ['AAA BC', 'BBB KK', 'CCC TD'] >>> uniqueItemsWithoutRev(["AAA BC","BBB KK","CCC TD","AAA KP","CCC TD"]) ['AAA KP', 'BBB KK', 'CCC TD'] When you walk the list forwards, the item that gets returned for the corresponding "key" is the item that is last found (as I don't check whether the item is already in the dict in the loop, but always just set), when you walk the list backwards, the item that is last found backwards (thus farthest in front) is returned. In case this doesn't matter (well, I guess it actually doesn't, as the OP only needs the first n chars, that's the reason for this function), you can easily leave out the reversed() and remove the constraint on Python 2.4. If you must have it in this order, and still use Python <2.4, you'd need to use something like oldlist[::-1], which will copy the list. reversed(list) does an optimization. HTH! -- --- Heiko. pgpUavJLshnS0.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: For loop extended syntax
On Sunday 20 March 2005 20:47, George Sakkis wrote: > Not always. Say for example that you're doing some 2D geometry stuff, and > later you have to extend it to 3D. In this case you may have to deal with > both 2D and 3D objects, and map the former to the latter when necessary. But this rather sounds like you'd want an adaptor iterator, like the following: >>> class AdaptPossible2D(object): ... def __init__(self,data): ... self.data = data ... def __iter__(self): ... for item in self.data: ... if len(item) == 2: ... yield item+(0,) ... else: ... yield item ... >>> for x,y,z in AdaptPossible2D([(1,2),(1,2,3),(3,4)]): ... print x,y,z ... 1 2 0 1 2 3 3 4 0 Using the above code makes it absolutely clear what you want, and doesn't need any new syntax which can be ambiguous like (x=0,y,z=0), etc. The above idiom also takes only constant extra space, as it doesn't duplicate the list during iteration. -- --- Heiko. pgpiKidxAK8Og.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: simultaneous copy to multiple media
On Sunday 20 March 2005 17:16, Claudio Grondi wrote: > Is there maybe a way to use a direct DMA > transfer to multiple target destinations > (I copy to drives connected via USB ports) ? Think about what USB stands for. Then reconsider whether you'll ever have the chance of writing truly simultaneously to several devices connected via USB... And then, as an extra exercise, think about why it takes so long when several different jobs are done in parallel, writing to devices connected via USB. Bus design... Don't they teach anything at uni these days? ;) -- --- Heiko. pgpMCGCKFMjC0.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: For loop extended syntax
Am Sonntag, 20. März 2005 22:22 schrieb George Sakkis: > Once more, the 2D/3D example was just that, an example; my point was not to > find a specific solution to a specific problem. And my point being: it's simple enough to give a general recipe (which my example was) without extending Python's syntax, so why extend the syntax and not just use a solution derived from that recipe that's working now (and is backwards compatible at least to 2.3), and which is also clear in itself? I'm not saying that your syntax looks "strange" or "bad", but there are means to do what you want to do now, without cumbersome syntax or duplicating code, and as such I'm -1 on syntactic sugar (TOWTDI and all)... Don't take this the wrong way, but I think introducing syntax is the wrong solution to a non-existant problem with the language. -- --- Heiko. pgpKzqC7Aa4ue.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: simultaneous copy to multiple media
Am Sonntag, 20. März 2005 23:16 schrieb Claudio Grondi: > 2) if I understand it right, an USB controller is connected to > to the PCI bus and there can be many separate USB > controller on one PC Yes, there may be more than one USB-controller in a PC, but this doesn't matter, they are all connected to the same bus (the PCI bus). This is a parallel bus, but also a bus which can only serve a single endpoint at a time. The frequency is normally 66 Mhz, so you get a theoretical 66*32 Mb/s over the PCI bus. But, this is only theoretical usage. Consider the EIDE-controller trying to write data into DMA memory which it has read from disk. It has to do the following to communicate with memory: 1) signal the DMA chip (which is also a device on the PCI bus) that it has data. This implies grabbing the PCI bus, making sure noone else is talking at the moment. 2) pass the data, 32 bit at a time, to the DMA chip, which places this data into main memory. 3) you may not grab the bus too long, as other devices might also want to communicate with some other device (e.g. the PIC, to signal an interrupt to the CPU). Thus, you have to free the bus after some time, and you have to forcibly give free the bus when some other device signals an interrupt. This also means starting transmission again after the bus has been successfully reacquired. 4) finally, after communication with the DMA-chip is done, signal the PIC via an interrupt that you wish the CPU to be signaled that it should do a software interrupt, so that the OS interrupt handler can be scheduled and can take the data from the DMA region (and do something with it). Now, even when the bus is fast, setting it up all still takes time, so you never get the theoretical throughput you might wish to see. Accessing the USB controller does the game the other way around; the OS uses the DMA-chip to stream the data onto the PCI bus for the controller to transmit. So, overall, adding more USB controllers to your PC only adds extra throughput until you reach the top limit of PCI (when the controllers start stealing bandwith from each other). > 3) the theoreticall speed of USB (430 MByte/s?) is much > higher as the experienced 15 MByte/s, probably due to slow > controller on the side of the external storage media, so > maybe even on one USB line I will have the chance to > use it full capacity connecting many slow devices > (I can't imagine, that USB goes down with the speed to > the speed of the slowest component connected, does it?) Well, 430 MB/s is only for USB 2.0. AFAIK, most devices (esp. storage devices) are still only USB 1.1 compliant, which makes this rate go down to a mere 40 MB/s or something close. > 4) with 45 MByte/s I could theoretically simultaneously > supply three separate data streams to three USB > controller writing with 15 MByte/s each out to the > external storage media. No, you can't. As I said in response to point 2, it doesn't matter what kind of bus you use, when the bus isn't meant to do real "broadcasts" or can actually talk to several devices simultaneously because all wires are duplicated a corresponding number of times, there's always overhead when switching between the devices. The bus must be acquired for communication with one device (so that the others won't simply go blabbering over the communication), then the data must be streamed, then the bus released again. This process takes time, and AFAIK, USB is pretty expensive (compared to data transmission speed) here, as USB guarantees that a packet reaches the endpoint when its transmitted over the wire (in the sense that it won't get lost because someone else was also talking). Now, when more devices come into play, this overhead becomes significant, and takes away quite some bandwith. For example, Ethernet takes another way. Ethernet simply says: when I have data which is transmitted while someone else was talking, throw away the resulting mess (a collision, remember those cool blinking lights on hubs?). Someone will retransmit it if it was important. > 5) watching the low CPU usage while writing to USB > shows me, that CPU-time is not a problem. No, it most certainly isn't. That's why modern computers always use a DMA-chip to do the heavy work of dealing with the hardware on external busses... ;) > P.S. Your message appears in my Outlook Express > as one having no content, but an attachment, so I can't > read it directly. Err, that's pretty strange. I can read my KMail written emails in pretty much any client that I have access to... So I guess this is a problem with Outlook Express not understanding MIME correctly, and not a problem on my side... ;) And, don't worry, I won't switch to -mode now. ;) -- --- Heiko. pgp6Uj3A40bZ4.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: winapi32.GetFileVersionInfo() - problem
> Do you actually think anybody will reply to your mail if you keep reposting at this frequency? It'll rather make most people here kill-file you. One post is enough; we've seen your problem, and it seems as though nobody here has a better solution than what Dennis Lee Bieber has already offered. Just to make sure you understand what he said, I'll repeat it here: Your DLL doesn't contain a resources section, which in turn contains the version information you're asking for. So, please start reading MSDN and the VC++ documentation on how to add this information to your DLL. If you wish to catch the exception that's raised (because the resource block isn't present), use something like the following: try: d = win32api.GetFileVersionInfo(fname,r"\") except: d = None if d is None: print "No version info in file!" else: -- --- Heiko. pgpcvIOsraTHA.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: mysteriously nonfunctioning script - very simple
Am Samstag, 26. März 2005 19:47 schrieb Sean McIlroy: > Why not try the following: >>> import datetime >>> x = datetime.datetime.now() >>> x datetime.datetime(2005, 3, 26, 21, 48, 13, 495765) >>> y = datetime.datetime(2005,3,26,21,50) # Wake me up today at 21:50 >>> y datetime.datetime(2005, 3, 26, 21, 50, 13) >>> time.sleep((y-x).days*60*60*24+(y-x).seconds+(y-x).microseconds*0.01) >>> print "I am past the timeout!" -- --- Heiko. pgpqu5qmTn3g4.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python
Am Samstag, 26. März 2005 20:43 schrieb Mark Tolonen: > On my system, for whatever reason, the .so library isn't present. I have > the python-devel package installed. I actually can't believe this; do ldconfig -p|grep "python" as root and look for any output. And remember that the shared library isn't installed by the devel package, but by the standard python package, as the binary /usr/bin/python is only a "stub", which chains to the python interpreter in the shared lib (at least for any distribution I know of, it would be braindead to link the command-line interpreter statically anyway). Sample output: heiko heiko # ldconfig -p|grep python libpython2.4.so.1.0 (libc6) => /usr/local/lib/libpython2.4.so.1.0 libpython2.4.so (libc6) => /usr/local/lib/libpython2.4.so libpython2.3.so.1.0 (libc6) => /usr/lib/libpython2.3.so.1.0 libpython2.3.so (libc6) => /usr/lib/libpython2.3.so heiko heiko # -- --- Heiko. pgprh13F5sG2y.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python
Am Samstag, 26. März 2005 21:36 schrieb Mark Tolonen: > I also (before I originally posted) did a "find / -name libpython*" with no > success. Looks like Redhat 9 ships with a statically linked version of > python. Hmm... Sorry to have thought otherwise... RedHat is braindead. :-) -- --- Heiko. pgpOOfyfBPNer.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use "__new__"?
Am Mittwoch, 30. März 2005 03:27 schrieb could ildg: > Thank you. > I'm clear after I read the doc: > If __new__() returns an instance of cls, then the new instance's > __init__() method will be invoked like "__init__(self[, ...])", where > self is the new instance and the remaining arguments are the same as > were passed to __new__(). > > If __new__() does not return an instance of cls, then the new > instance's __init__() method will not be invoked. > > __new__() is intended mainly to allow subclasses of immutable types > (like int, str, or tuple) to customize instance creation. Remember that __new__() can also be used to create singletons (to return a pre-existing instance in case some form of argument matches, for example): class Singleton(object): __buffer = {} def __new__(cls,somearg): if somearg not in cls.__buffer: cls.__buffer[somearg] = super(cls,Singleton).__new__(cls) return cls.__buffer[somearg] def __init__(self,somearg): self.__somearg = somearg def __repr__(self): return "" % (self.__somearg,hex(id(self))) >>> x = Singleton(1) >>> y = Singleton(2) >>> z = Singleton(1) >>> print x >>> print y >>> print z >>> x is y False >>> x is z True >>> y is z False You could extend the above example quite easily to deal with deallocation (a reference to each created singleton is retained using the above class, always, as long as the program is running) and also to make it threadsafe or to disable initialization in case the singleton has already been initialized before. -- --- Heiko. pgpR2HcFvUtvj.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use "__new__"?
Am Mittwoch, 30. März 2005 04:36 schrieb Heiko Wundram: > You could extend the above example quite easily to deal with deallocation > (a reference to each created singleton is retained using the above class, > always, as long as the program is running) and also to make it threadsafe > or to disable initialization in case the singleton has already been > initialized before. Just to post a complete example of a Singleton class which works in a multithreaded environment, and allows you to update future instances (a sample, untested implementation): import threading import weakref class SingletonBase(object): __buffer = {} __bufferLock = threading.RLock() def __new__(cls,*args,**kwargs): cls.__bufferLock.acquire() try: inst = cls.__create_new__(buffer,*args,**kwargs) if not hasattr(inst,"_SingletonBase__instanceLock"): inst.__instanceLock = threading.RLock() inst.__initialized = False return inst finally: cls.__bufferLock.release() @classmethod def __create_new__(cls,*args,**kwargs): return super(SingletonBase,cls).__new__(cls) def __init__(self,*args,**kwargs): self.__instanceLock.acquire() try: if not self.__initialized: self.__initialize_new__(*args,**kwargs) self.__initialized = True else: self.__update_old__(*args,**kwargs) finally: self.__instanceLock.release() def __initialize_new__(self,*args,**kwargs): pass def __update_old__(self,*args,**kwargs): pass class Singleton(SingletonBase): @classmethod def __create_new__(cls,buffer,somearg): inst = buffer.get(somearg,lambda: None)() if inst is None: inst = super(Singleton,cls).__create_new__(cls) buffer[somearg] = weakref.ref(inst) return inst def __initialize_new__(self,somearg): print "Initializing new instance." self.__somearg = somearg def __update_old__(self,somearg): print "Updating old." assert somearg == self.__somearg # Initialize three singletons. print "Creating singletons for 1, 2, 1." x = Singleton(1) y = Singleton(2) z = Singleton(1) # Print them out. print "\nThree singletons: x, y, z." print repr(x) print repr(y) print repr(z) # Assert that x is not y, and x is z. print "\nx is y, x is z" print x is y print x is z # Delete names, and make sure weakrefs are unbound. print "\nRemove all three singletons." del x del y del z # Recreate singleton for value 1. print "\nRecreating singleton for value 1." x = Singleton(1) y = Singleton(1) # Print them out. print "\nNew Singleton(1): x, y." print repr(x) print repr(y) # Check that x is y. print "\nx is y" print x is y The above program prints the following output when run: Creating singletons for 1, 2, 1. Initializing new instance. Initializing new instance. Updating old. Three singletons: x, y, z. <__main__.Singleton object at 0xb7bfbc6c> <__main__.Singleton object at 0xb7bfbcac> <__main__.Singleton object at 0xb7bfbc6c> x is y, x is z False True Remove all three singletons. Recreating singleton for value 1. Initializing new instance. Updating old. New Singleton(1): x, y. <__main__.Singleton object at 0xb7bfbc6c> <__main__.Singleton object at 0xb7bfbc6c> x is y True HTH! -- --- Heiko. pgpQKQoZkoCMz.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple thread-safe counter?
Am Samstag, 2. April 2005 22:28 schrieb Paul Rubin: > I'm starting to believe the GIL covers up an awful lot of sloppiness > in Python. I wonder if there could be a decorator approach: > > @synchronized > def counter(): >t = itertools.count() >while True: > yield t.next() Of course there could: def synchronized_iterator(f): def wrapper(*args,**kwargs): class iterator(object): def __init__(self,f,args,kwargs): self.iter = f(*args,**kwargs) self.lock = threading.RLock() def __iter__(self): return self def next(self): self.lock.acquire() try: return self.iter.next() finally: self.lock.release() return iterator(f,args,kwargs) return wrapper @synchronized_iterator def create_counter(): t = itertools.count() while True: yield t.next() or counter = synchronized_iterator(itertools.count) I used a class-based approach, as I don't want to destroy the semantics of calling the returned wrapper(), which should've already instantiated the wrapped generator object (which doesn't happen when making wrapper() a generator itself). -- --- Heiko. pgp4kxA2GZNHL.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple thread-safe counter?
Am Sonntag, 3. April 2005 00:57 schrieb Heiko Wundram: > > or Make that: create_counter = syncronized_iterator(itertools.count) and counter = create_counter() to create the actual counter regardless of iterator. -- --- Heiko. pgpuQ5CRv1IKe.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Python Cookbook
Hi all! I've received my copy of the Python Cookbook two days ago, and just thought that I might independently commend all you editors and recipe designers out there to an excellent book! I've thoroughly enjoyed reading the introductions in each chapter, and although I've been programming in Python for four years now, I've seen quite a few idioms that are new for me as well. The book is pretty much just like this newsgroup: surprises me each and every time again how many smart people's comments are contained within. :-) Keep up the good work! And thanks Alex for making the second edition possible! -- --- Heiko. listening to: Wir Sind Helden - Ruessel an Schwanz see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpg0wsEfR0XZ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Raise Error in a Module and Try/Except in a different Module
Am Montag, 4. April 2005 12:11 schrieb Issa-Ahmed SIDIBE: Try: > import ModuleA > ... > class(): >... >try: a = ModuleA.FUNC1() ^^ <-- Actually call the method. >except ModuleA.EXCP1: print 'catch' HTH! -- --- Heiko. see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpSul6uhjT2y.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: import and scope inconsistency?
Am Montag, 4. April 2005 12:23 schrieb Jim: > I can call MyFiles methods inside methods of the Brances classes. > I cannot call Numeric methods inside methods of the Brances classes. > > 1. I was surprised I could call MyFiles methods in Branches methods. > 2. Since I was used to using modules imported in the parent module I was > surprised I couldn't use Numeric methods. 1. I can't answer you this one without looking at the actual code, but 2. You can never call any methods/classes which you imported in a "parent" module (actually, there's no such motion as parent module, as each module has its own namespace, and references to this namespace may appear anywhere else in another module). In case this worked sometime ago and you didn't explicitly import the module in the "child" module, you silently did something like the following: Mod1.py --- import Numeric import Mod2 # Put the namespace (module object) in another namespace Mod2.Numeric = Numeric Mod2.py --- What you need for your simulation program is probably something like the following: Simulation.py - import MyFiles import Branches import Numeric print MyFiles.Branches is Branches # True print MyFiles.Numeric is Numeric # True print Branches.Numeric is Numeric # True MyFiles.py -- import Branches import Numeric print Branches.Numeric is Numeric # True Branches.py --- import Numeric HTH! -- --- Heiko. listening to: aenima_13_aenima.mp3 see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgp3EJqOZ4rfI.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: import and scope inconsistency?
You're putting a Reply-To header in your posts to the mailing-list, but the Reply-To address bounces. Please correct: on't put in a Reply-To header, or at least put in some address that doesn't bounce. -- --- Heiko. listening to: aenima_15_Third Eye.mp3 see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgp4LVfom4iRJ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: boolean -> DNF
Am Montag, 4. April 2005 15:08 schrieb Alex Polite: > I'd like to skip BoolStuff and do it all in python but I have no idea > where to start. Anyone out there with a PhD in computer science that > can give me a starting point? I once wrote a library which implemented parsing boolean expressions (with a simple homegrown parser) and reprinting the tree (to print it in DNF-Form is a pretty simple algorithm once you have the tree structure, I didn't implement this, but if you ask me I will). I don't have access to it at the moment (because I created it at home), but I'll send it to you tonight if you just contact me off-list. -- --- Heiko. listening to: Nine Inch Nails - The Wretched see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpMqLIytwLHn.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: setup distributed computing for two computer only
Am Montag, 4. April 2005 21:27 schrieb [EMAIL PROTECTED]: > Google for: Python Remote Objects or Python XMLRPC -- --- Heiko. listening to: Nine Inch Nails - The Downward Spiral see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpbsPKhjKOEY.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: help with python-devel!!!
Am Montag, 4. April 2005 20:54 schrieb John Ridley: > The OP mentioned that urpmi couldn't find a package by that name. So it > might be worth querying for "libpython" if that fails: This is why why I don't use a binary distribution... :-) (Differences in) Naming makes getting at devel-packages a guessing-game at best. -- --- Heiko. listening to: Nine Inch Nails - Hurt see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpIlx4oN486w.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing TEXT color from python
Am Montag, 4. April 2005 21:59 schrieb GujuBoy: > how can i do this...and hopefully without including any external > modules. It depends. Under *NIX, have a look at the curses module. Under Windows, Google for ANSI.SYS and read up on Escape Sequences, or check out the curses for Windows implementation that's floating around somewhere on the net, I don't know the URL. HTH! -- --- Heiko. listening to: Nine Inch Nails - Somewhat Damaged see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpkgPO1LUU9T.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: setup distributed computing for two computer only
Am Dienstag, 5. April 2005 11:22 schrieb Irmen de Jong: > > Python Remote Objects > > ^^^ what Heiko said :) *biggrin* -- --- Heiko. listening to: Tool - Lateralus - 1 The Grudge.mp3 see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpKv3ALoPbZi.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Python backend binding to PAM, NSS or pppd
Hey all! Before I start hacking away, I'm looking for a Python backend binding for libpam or libnss, or a python binding for the pppd plugin mechanism. I'm trying to set up an SQL authentication scheme for virtual user accounts used for mail and PPTP-VPN-access, and I'd love to do the authentication bit in Python. And, yes, I know about pam-mysql and nss-mysql, but both projects are old and unmaintained, and I use Oracle as backend DB anyway. If anybody knows of any project which has implemented a part of this, I'd love to hear about the effort... -- --- Heiko. listening to: Wir Sind Helden - Du Erkennst Mich Nicht Wieder see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgp9MT0rTAPsW.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check whether a list have specific value exist or not?
Am Samstag, 9. April 2005 11:37 schrieb Michael Spencer: > praba kar wrote: > > I want to check a list have specific > > value or not. So If any one know regarding this > > mail me > A minute of two experimenting, would then lead you to: > >>> l = [1,2,3,4,5] > >>> l.index(3) > > 2 Or, if its that you just want to know whether a value is somewhere in an iterable: >>> l = [1,2,3,4,5] >>> 4 in l True See how there is special syntax to call the __contains__ method of the iterable automatically. -- --- Heiko. listening to: Pearl Jam - Rearviewmirror see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgp73dFMahMxZ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: change the date string into timestamp
Am Samstag, 9. April 2005 11:38 schrieb praba kar: > In Php strtotime() will change a date > string into timestamp. I want to know which > python function will change a date string > into timestamp. You want the standard library function strptime from the time module (in case it's a timestamp you're looking for), otherwise have a look at the library documentation for the datetime module, which gives you a datetime class which can also be constructed strptime-like from a string. Example: >>> date = "Fri, 8 Apr 2005 09:22:14 +0900" >>> timetuple = time.strptime(date,"%a, %d %b %Y %H:%M:%S +0900") >>> timetuple (2005, 4, 8, 9, 22, 14, 4, 98, -1) >>> timestamp = time.mktime(timetuple) >>> timestamp 1112944934.0 The timestamp is in local time, as is the timetuple (I've hardcoded the +0900, there's no format string which will parse the timezone parameter, and recode the time to UTC, it's up to you to do that). -- --- Heiko. listening to: Pearl Jam - Spin The Black Circle see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpAlMVOkrzJS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: change the date string into timestamp
Am Samstag, 9. April 2005 12:10 schrieb Fredrik Lundh: > >>> from email.Utils import parsedate_tz > >>> parsedate_tz(formatdate(x, localtime=1)) > > (2005, 4, 8, 14, 22, 14, 0, 1, 0, 7200) Very cool! Learning something new every day! -- --- Heiko. listening to: Pearl Jam - Dissident see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpSKpnmAtkYS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: question about functions
Am Freitag, 15. April 2005 06:44 schrieb chris patton: > In other words, can I call the arguments from a list? Yes. >>> def testfunc(*args): ... print args[0] ... print args[1] ... >>> testfunc("this is","a test") this is a test Read up on positional and keyword arguments (the latter are something that'd make me choose python over anything else instantly) in the Python tutorial and documentation. -- --- Heiko. listening to: Pearl Jam - Given To Fly see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpJHTrjaYbYA.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing to log file when script is killed
Am Samstag, 30. April 2005 14:26 schrieb [EMAIL PROTECTED]: > If you run on unix you can use the signal module to intercept a kill - > see http://docs.python.org/lib/node368.html for a quick example You cannot intercept a kill (that's the whole meaning of SIGKILL, rather than SIGTERM)... Read up on UNIX signal handling. But, for the rest: you could intercept SIGTERM, log a message, and raise a SystemExit exception. That should do the trick. -- --- Heiko. see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpcjkH9bj8ZO.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Cannot form correctly the FORM part of the header when sending mail
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 03.09.2013 09:48, schrieb Ferrous Cranus: > Si there a workaround for that please? Yes, use/setup your own mailserver. Google will not allow you to send as ("i.e., From:") an arbitrary address besides the one you've authenticated as. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSJyUuAAoJEDMqpHf921/SksoIAJyFyYDN9zj/SypXERj+W1wK fRuby0EyfWWMQayJ7SlbiSUzK3OF1ZVxO5s3WqGdXWI2WhXrrZbltuMyHedlBcqy Dl9F1MtpItg01weICAYJCNcTNm649PCAuc47zbGahE7tDeJwU9xNlgEgXfnpx+eX RvtyYAJlYnz5MTfftYZS9AxxEbaA+k5TNHcVE+5m3YX3Uno6rW+T19H4z4wC374K MHxN4jS+z/qaZ+fDIkK6Uq8aRC5PA9pI37iTD5dJFikKugcp/9AqssnsEUkhMAGV dcGPJnI1tiGrSLY6Q8q31DpkAlO79ETA4ag0yGvnjtmR/ZZjENlb2Ikls7JOA9Y= =JDjl -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 16.09.2013 13:21, schrieb Denis McMahon: > If he's trying to prove communication works, he might be better off > using a message subject of "test" and a message body of "this is a > test message". Generally, he might be best off if he didn't use os.system() with string-interpolated (without escaping or any such) and user-specified (!) parameters to send out the mail using mailx though a sub-shell. This begs of using his mailer script for code injection as his web-server user, and I'm amazed that nobody has commented on that so far. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNuxTAAoJEDMqpHf921/Sd8IH/2BcapK/dNqbs/PDz3LZLiUS JYYmNaWSjui7KYJsA/A8R3XVaM0eyHkYI8dr8Jx6hPdPJyeE27MCKddF3GlYs17Z iO1AydR2J8kYjXgVLrCWtfH3taB6ryUko6sOe1j/u0hYbQOATxuBPvxTVK4Wmi85 1m8unw9NvlTelAREg6WLudqpE9i115dns87+FTNcgNd3ieppJw+Cv2Mp6z3Yn3he y0W9yMqH1LV4oW/6arZVVIcaWDHCb1I0L++aC8JLnOHYz1osf+34BbHHBcY6Qkty reon+sWKwrlJ56o8Zi1Lx97ymxXxuvUtJS/5WGpRh/XLWYVBGCX3XA42DKqscQk= =xENG -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 16.09.2013 13:37, schrieb Ferrous Cranus: > What i want now is to be able to alter the hostname of my server so > the mails wont indicate that they derive from superhost.gr as they > aare now sen in the mail headers. There is no way to do that, as the Received:-header which you complain about is inserted by Google mail servers. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNu8bAAoJEDMqpHf921/SFjwH/RXH79ynaWTkdeYWc3koAPvv wQJKaiYy0FMJgV0JoZqWcg6xc/gEfoyBVvMlxTjSI9Jq44Ay6p3xYl4mCV9Oxplc nx3SD8XKE6HV8H8cdUE+MAVxcI4mhz43so6yG7vWFJskuKZMC4zCwnP3F2Wt3zNK EpgYyyKSCG+5KOhnOryw3lVQ0qlsqp02/cEQbn3iWtoe5ojh8qFr+bHL1vs02gtK 16YgKXre+69ne1hs4Hcyj1OKzYHU+YJmP6WTbdIXFXv1ujS3pf0vjpPWLX8f02Y1 n0HHBL0hWvm9+rbxYXera75jQUqY0v042fDjajhKNa/Sq36OBeoW6vt5hysDBxc= =4HLT -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 16.09.2013 14:11, schrieb Ferrous Cranus: > But even so, if we alter for example the hostname of our server to > a different name then wouldn't Google use that to identify the > server thus protecting the real identity(hostname that is) of the > server that initiated the connection? Why on earth would you want to do that? Mail routing headers are there for a reason. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNvbTAAoJEDMqpHf921/SUMoH/2iX9pw0DiOWqHzAj1igbswY tlQVigpz8eprFpsl84JW0+NAOFcpy65VdmwynJ57+qhHvChpdygGoNYjtStP37nF oYbMNHs2gRA+dbhl3xxjedGgIzQinGM7aiy+7ZGU/KIGHorMykV0eUDQaObklFNb oepbNMu1yo2U2PWyBHxlH8iehyECFdeKfLRJX6YrkT5jSS7EKKn6UuaCLKRMYJNN sClGe4J5x5GnIsPtPSWK73rdmYtY/vLmM9P4tDKCBAJvdW5nU52EXLlMNzWu8lPS wvg6bor1/meYPxfzIcmIvKTiYZ+omkmQ8iPkOGEupPCKp8SRB9J2iq8nQA0mYo4= =1cDc -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 17.09.2013 01:41, schrieb Steven D'Aprano: > I cannot fathom for the life of me a legitimate reason for your > website to use a fake IP address and hostname when sending email. In addition to that: it's amazing that Nikos thinks TCP will still work in the presence of spoofed IP addresses. Email without TCP is a challenge, at the least. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9 6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY= =K/XL -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Tryign to send mail via a python script by using the local MTA
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 17.09.2013 13:55, schrieb Joel Goldstick: > At least if you want to add to this nonsense, read each of the > (several?) dozen entries. Actually, I have read each of the troll cycles (just as I read much of clp, although I haven't participated much for the last five years), and found most of them to be rather interesting reads (in their digression from the original topic). And: I actually find it rather valuable answering indirectly to things noticed "along the ride" (or reading what other people answer indirectly in the same manner) - see my post in this thread where I pointed out that the original code actually does not sanitize inputs to a shell command to send mail. But, again, your impression may differ, and I can respect that. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSOEl/AAoJEDMqpHf921/SAJQIAI48Kzz0js1QqMDkotmMZfdE XJYwsWlRXtaPhRy1VEGKHiSgCEd71/IVDUOPEv5TuJMy9zfsW1McexrYMW0NW63J RiAlDmLSITfdPRYqPgmOTA4MqgJ3V2/oAzOpYXwPqs8Qdt92AX5Tr5itDFgua18T TSdsD4gNudtIMUBkACzMjJKGyxrHvFFhGpUHlFh5swrZhflaGm1TuCWwz3ojTSbG yoQRPe1ylSjcxkJesaKXR8mIaUMq4mrUaChBe+FwoCJXXs8kkX/EO3KULvKCxQGU lzsom+b/eTaxB/ttyHwbt7QSsYq1ko2fIeqqDD/jmhTpg5gshOC+JHLs3bUkmMw= =sTJq -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Having both if() and for() statements in one liner
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 17.09.2013 15:21, schrieb Ferrous Cranus: > ... there must be written on soem way. You've already given yourself the answer in the initial post. The Python way to write this is: if person == "George": for times in range(5): ... Why not just use what works and get some actual work done? - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSOF0gAAoJEDMqpHf921/Sv0oH/AyuaOk5sFlx4j7CKzv4Bb9i +REyAtLJXpgcziviFXjIbnPsNLtGqMU6yOgp9OV7LGwfn0mnZtmI+SoYp08t7G9U 3WSMC6BOCugg419EEMmf+Gkf4fWvv/aZYWBTd8MhyiJLsQ9R7Sg9LlGYheDQ6m+S RwWpYSHYCaJu3iy2xBJ+8AqQjOqACcMREtW1Rt1uHiydO93Dn2Abm0XLq11psYeR OV3sftEJ2EpMEcR4I/HLx95KWIh7wvQcZywTF9y+pe1uOnLrKW/1NdkUxNdkMofy RBNOjYJjT9JAnB2UHI1wVtbipwSi4A4zIIYsE6exv4s1IjnInrVERdDOOlqjwzQ= =rxPO -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: I haev fixed it
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 01.10.2013 13:06, schrieb Νίκος: > But it seems you don't want to provide an explanation although i > think you might have a theory. You need a theory? 1) Your password(s) is/are leaked (see the URL referenced somewhere before, and IIRC you also posted your GMail password sometime ago), and 2) you did password-reuse, so that by an attacker getting access to one password, more than one of your accounts was compromised. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSSrIKAAoJEDMqpHf921/SO+UH/iujBSt7ZXmXAIAHgHXoKH0Q Qxvzi2L1pCXcXvEE4yeUI0g0TiYD9B88Q5eRyCegWWm2BwpOjx7KLNBkMqQeiI6H M52L/ulXwMkwVq0HTn6YPNncReQrPMu2V5xQaKWhfVhBnWLZnZYm1n7WZse9M2Sr 9KaAkZ4j2jlHozJ9tAGXnIt/9bj6MM3SQPuG1b68qSWThisUhvTcbrDkm3e4KDoq I9i9kEF93XPLYeOMefEOksm51vKjpDWFlRu20Vqy5quYxDHpUU/5e04Z6doz0py8 6XhR892g4zetQ3OwtzxQOKunwaLOvSg9VtXfIn7ElBkCE0v/XbCxTnO/oBLcb7g= =I1kO -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: I haev fixed it
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 01.10.2013 14:06, schrieb Νίκος: > i know about the link you mentioned and i have deleted the source > code from there. Guess what: Google keeps a cache. See here: http://webcache.googleusercontent.com/search?q=cache:http://superhost.gr/~dauwin/cgi-bin/metrites.py So if you haven't changed your password(s), you'd better do that now. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSSrwRAAoJEDMqpHf921/SY/MH/3pf9ZdHCXuu84urCodUyBrQ RVRbVN1lXAzCXY1nyPGfzANOsraXLzRDe0j9ZBfHbEaZR19Hvl4DOf8+RJfRl8jg LWCsgIIVb2fWWVLrx1CU3oz47sVfy1vGOp8XRiIqjcDKa+zOtyqqlxIolKCFM6CL /YsHnb1/9JE1zn07WaKYJTi1/9+uptaQPR9kNzOssv1TpvRiJ+4H1oO67Px6tpdj VchpEirkV7CaD39mD9BLEoB24FhEX+NSNYPRJx89ivC+MENpNUp6n5vVjQ+ciXI/ NvJJxBalypi/DLNaCR/up2B2018ebH+3ByDv3xO+UnbS6MYx5YVppstilvkvr1c= =2VTx -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 02.10.2013 13:03, schrieb Νίκος: > I have to make some money and that needs for some reason to happen > now as we speak, so i have no alternative than to hop into a car > and learn to drive during the process, hoping i will not bang-smash > the car. I'm really sorry for the fact that it seems as though your livelyhood really does depend on your current mess, but: this is not the way to learn to administer servers or how to program. Do that first in one way or another - and then start making money off it. And, from my personal experience, you are exacerbating your problems by behaving and/or acting as you currently are, as generally at some point in time the mess you currently leave behind - which you permanently choose to ignore - will start to become a liability for the rest of your livelyhood, which _will_ then get you in real trouble. - -- - --- Heiko. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSTATwAAoJEDMqpHf921/SK54IAJvUF+3nTJq5nKPN2s1WdQbz hOvqMThrhBE7BG6ybF8TfbKpLmZ+20cZExVzn4Xy9PPGe+WTrt6UR8+UizSst1Vs EgZ0DrmWb+WRN+nUZPyL45psDMaHdi1bQy0ReVGbav1faG9Y9tAMZ2KEQwfrnmZz CJ9mTJ95IbuB3iizCdlUOT2qCzhGPyCsx1ejR6IkKofKaO0QU712V7rHN9u/xdlJ v687pSzeNuRxWP9Rdlp25FIVDgj3oNGrK9HXrYUyra9TXSyZW3XTWbUjwriNMxer 8B00cngvLTEf14AmMeIkno7GvTP5QWq7yNul7n85Pq6ZXJKWLjVLodKwYndSf9I= =AOdw -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: SSE4a with ctypes in python? (gcc __builtin_popcount)
Am 31.10.2011 04:13, schrieb est: Is it possible to rewrite the above gcc code in python using ctypes (preferably Win/*nix compatible)? No; the (gcc-injected) functions starting with __builtin_* are not "real" functions in the sense that they can be called by calling into a library, but rather are converted to a series of assembler instructions by the compiler directly. Wrapping this (distance) primitive by writing a C-module for Python, thus exposing the respective gcc-generated assembler code to Python through a module, won't yield any relevant speedups either, because most of the time will be spent in the call sequence for calling the function, and not in the actual computation. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 15:47, schrieb Robert Kern: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) Not possible in the general case (as the right-hand side might be an arbitrary iterable/iterator...). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 16:42, schrieb Roy Smith: The exception was raised when i() returned it's third value, so saying "expected 2, got 3" is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. Please explain how that error message (in case you're not aiming at the actual count of elements in the source) differs from the curent wording "too many values", as you're simply displaying "expected n, got n+1" where n is visible from the immediate exception output... -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
Am 02.01.2012 14:25, schrieb Νικόλαος Κούρας: On 23 Δεκ 2011, 19:14, Νικόλαος Κούρας wrote: I dont know why this line host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes and some other times works ok retrieving the hostnames correctly. Please i need some help. My webpage doesn't work due to this error... The error "herror: (1, ...)" says it all: the DNS-name (i.e., the .in-addr.arpa name) you're trying to resolve is unknown. Not all hosts (or rather, IPs) on the internet have reverse lookups: try the IP 81.14.209.35 from which I'm posting, and dig/nslookup will tell you that it has no reverse resolution, which would result in gethostbyaddr() throwing an herror-instance. Basically: make the reverse lookup conditional by wrapping it in a try:/except herror: and assigning an appropriate default for host in case reverse lookup fails. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoid race condition with Popen.send_signal
Am 03.01.2012 02:19, schrieb Adam Skutt: On Jan 2, 6:09 pm, Jérôme wrote: What is the clean way to avoid this race condition ? The fundamental race condition cannot be removed nor avoided. Ideally, avoid the need to send the subprocess a signal in the first place. If it cannot be avoided, then trap the exception. Yes, it can be avoided, that's what the default SIGCHLD-handling (keeping the process as a zombie until it's explicitly collected by a wait*()) is for, which forces the PID not to be reused by the operating system until the parent has acknowledged (by actively calling wait*()) that the child has terminated. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoid race condition with Popen.send_signal
Am 03.01.2012 14:40, schrieb Adam Skutt: On Jan 3, 7:31 am, Heiko Wundram wrote: Yes, it can be avoided, that's what the default SIGCHLD-handling (keeping the process as a zombie until it's explicitly collected by a wait*()) is for, which forces the PID not to be reused by the operating system until the parent has acknowledged (by actively calling wait*()) that the child has terminated. No, you still can see ESRCH when sending signals to a zombie process. Code that sends signals to child processes via kill(2) must be prepared for the call to fail at anytime since the process can die at anytime. It can't handle the signal, so it's treated as if it doesn't exist by kill(2) in this case. However, you don't have to worry about sending the signal to the wrong process. Getting an error on kill (which you can catch) is not about the race that the posters were speculating about (i.e., sending the signal to the wrong process), and that's what I was trying to put straight. The only advice that I wanted to give is: 1) before calling wait to collect the child, call kill as much as you like, and in case it errors, ignore that, 2) after calling wait, never, ever kill, and you don't need to, because you already know the process is gone. There's no race possibility in this, _except_ if you alter handling of SIGCHLD away from the default (i.e., to autocollect children), in which case you have the possibility of a race and shooting down unrelated processes (which the discussion was about). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hash stability
Am 14.01.2012 10:46, schrieb Peter Otten: Steven D'Aprano wrote: How many people rely on hash(some_string) being stable across Python versions? Does anyone have code that will be broken if the string hashing algorithm changes? Nobody who understands the question ;) Erm, not exactly true. There are actually some packages out there (take suds [https://fedorahosted.org/suds/], for example) that rely on the hashing algorithm to be stable to function "properly" (suds uses hash() of strings to create caches of objects/XML Schemas on the filesystem). This, in a different context, bit me at the end of last week, when required to use suds to access EWS. I'd personally start debating the sensibility of this decision on the part of the suds developers, but... That's not the question. ;-) -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list