Re: Why is there no platform independent way of clearing a terminal?

2010-07-28 Thread Ulrich Eckhardt
Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have > asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? There are two kinds of programs: 1. Those that process input to output. If one of those

Re: need help: Is there is a way to get someone's calendar from mail exchange server with python

2010-07-15 Thread Ulrich Eckhardt
aimeixu wrote: > I really need help to figure out a way to get someone's calendar from > mail exchange server with python. You can implement any network protocol with Python, see e.g. the struct library. However, it would be easier to use an existing protocol implementation. When you say "mail exc

Re: pythonize this!

2010-06-15 Thread Ulrich Eckhardt
superpollo wrote: > ... s += i**2 > ... if not (i+1)%5: > ... s -= 2*i**2 > ... if not i%5: > ... s -= 2*i**2 if not (i % 5) in [1, 2]: s += i**2 else: s -= i**2 Untested code. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR

Re: Reading file bit by bit

2010-06-07 Thread Ulrich Eckhardt
superpollo wrote: > mine goes like this: > > >>> bin(192) > Traceback (most recent call last): >File "", line 1, in > NameError: name 'bin' is not defined Yep, one of mine, too. The "bin" function was new in 2.6, as were binary number literals ("0b1100"). Uli -- Sator Laser GmbH Geschäft

Re: Reading file bit by bit

2010-06-07 Thread Ulrich Eckhardt
Peter Otten wrote: > Ulrich Eckhardt wrote: >> Says Python: >> >>>>> bin(192) >> '0x1100' > > Hmm, if that's what /your/ Python says, here's mine to counter: > >>>> bin(192) > '0_totally_faked_binary_0

Re: Reading file bit by bit

2010-06-07 Thread Ulrich Eckhardt
Nobody wrote: > On Mon, 07 Jun 2010 02:31:08 -0700, Richard Thomas wrote: > >> You're reading those bits backwards. You want to read the most >> significant bit of each byte first... > > Says who? Says Python: >>> bin(192) '0x1100' That said, I totally agree that there is no inherently rig

Re: Reading file bit by bit

2010-06-07 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: >data = f.read() >for byte in data: >for i in range(8): >bit = 2**i & byte >... Correction: Of course you have to use ord() to get from the single-element string ("byte" above) to its integral value firs

Re: Reading file bit by bit

2010-06-07 Thread Ulrich Eckhardt
Alfred Bovin wrote: > I'm working on something where I need to read a (binary) file bit by bit > and do something depending on whether the bit is 0 or 1. Well, smallest unit you can read is an octet/byte. You then check the individual digits of the byte using binary masks. f = open(...) da

decorating a memberfunction

2010-06-02 Thread Ulrich Eckhardt
Hi! I have a class that maintains a network connection, which can be used to query and trigger Things(tm). Apart from "normal" errors, a broken network connection and a protocol violation from the peer are something we can't recover from without creating a new connection, so those errors should "s

functools.wraps and help()

2010-06-02 Thread Ulrich Eckhardt
Hi! When I use help() on a function, it displays the arguments of the function, along with the docstring. However, when wrapping the function using functools.wraps it only displays the arguments that the (internal) wrapper function takes, which is typically "*args, **kwargs", which isn't very usef

Re: Question about permutations (itertools)

2010-05-31 Thread Ulrich Eckhardt
Vincent Davis wrote: > I am looking for the most efficient (speed) way to produce an an > iterator to of permutations. > One of the problem I am having it that neither combinations nor > permutations does not exactly what I want directly. > For example If I want all possible ordered lists of 0,1 of

Iterating over dict and removing some elements

2010-05-11 Thread Ulrich Eckhardt
Hi! I wrote a simple loop like this: d = {} ... for k in d: if some_condition(d[k]): d.pop(k) If I run this, Python complains that the dictionary size changed during iteration. I understand that the iterator relies on the internal structure not changing, but how would I str

Re: inherit from data type

2010-05-11 Thread Ulrich Eckhardt
Richard Lamboj wrote: > "How knows python that it is a float, or a string?" Sorry this was bad > expressed. I want to create a new data type, which inherits from float. I > just know the "dir" function and the "help" function to get more > infromations about the class, but i need to get more inform

Re: inherit from data type

2010-05-11 Thread Ulrich Eckhardt
Richard Lamboj wrote: > i want to inherit from a data type. How can i do this? Can anyone explain > more abou this? Other than in e.g. C++ where int and float are special types, you can inherit from them in Python like from any other type. The only speciality of int, float and string is that they

Re: Iterating a sequence two items at a time

2010-05-11 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: > I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4), > (5,6). I can of course roll my own, but I was wondering if there was > already some existing library function that already does this. > > > def as_pairs(seq): > i = ite

Iterating a sequence two items at a time

2010-05-11 Thread Ulrich Eckhardt
Hi! I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4), (5,6). I can of course roll my own, but I was wondering if there was already some existing library function that already does this. def as_pairs(seq): i = iter(seq) yield (i.next(), i.next()) Question to this cod

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Ulrich Eckhardt
Nico Schlömer wrote: > So when I go like > > for item in list: > item[1].sort() > > I actually modify *list*? I didn't realize that; I thought it'd just > be a copy of it. No, I misunderstood your code there. Modifying the objects inside the list is fine, but I don't thing you do that, provi

Re: itertools: problem with nested groupby, list()

2010-05-04 Thread Ulrich Eckhardt
Nico Schlömer wrote: > I ran into a bit of an unexpected issue here with itertools, and I > need to say that I discovered itertools only recently, so maybe my way > of approaching the problem is "not what I want to do". > > Anyway, the problem is the following: > I have a list of dictionaries, som

Re: Why this compile error?

2010-03-19 Thread Ulrich Eckhardt
Jimbo wrote: > Can you help me figure out why I am getting this compile error with my > program. The error occurs right at the bottom of my code & I have > commented where it occurs. [...] > def main(): > programEnd = False; > > while (programEnd == False): > #ERROR HERE?? - Error=

Re: import antigravity

2010-03-16 Thread Ulrich Eckhardt
Chris Rebert wrote: > You're a bit behind the times. > If my calculations are right, that comic is over 2 years old. import timetravel Uli -- http://mail.python.org/mailman/listinfo/python-list

Re: dll in project?

2010-03-15 Thread Ulrich Eckhardt
Alex Hall wrote: > On 3/15/10, Ulrich Eckhardt wrote: >> Alex Hall wrote: >>> I have a dll I am trying to use, but I get a Windows error 126, "the >>> specified module could not be found". Here is the code segment: >>> nvdaController=ctypes.

Re: dll in project?

2010-03-15 Thread Ulrich Eckhardt
Alex Hall wrote: > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") In addition to Alf's answer, this can also happen when the OS can't fin

Re: odd error

2010-03-09 Thread Ulrich Eckhardt
Alex Hall wrote: > Now, though, when I press ctrl-shift-c (keystroke 11), nothing > happens. Control-C sends a special signal to the console, like Control-Break. > Pressing any other keystroke after that will crash the program > with some sort of Python internal com server exception that I > have

Re: indentation error

2010-03-05 Thread Ulrich Eckhardt
asit wrote: > pattern = raw_input("Enter the file pattern to search for :\n") > commandString = "find " + pattern > commandOutput = commands.getoutput(commandString) > findResults = string.split(commandOutput, "\n") > print "Files : " > print commandOutput > print "=

Re: while loop with the condition used in the body

2010-02-24 Thread Ulrich Eckhardt
Peter Otten wrote: > Duncan Booth wrote: >> for rq in incoming_requests(...): >>handle_request(rq) > > ...and a likely implementation would be > > def incoming_requests(...): > while True: > rq = ... # inlined version of get_request() > if not rq: > break >

while loop with the condition used in the body

2010-02-24 Thread Ulrich Eckhardt
Hi! I'm looking for a way to write code similar to this C code: while(rq = get_request(..)) { handle_request(rq); } Currently I'm doing while True: rq = get_request(...) if not rq: break handle_request(rq) in Python 2.6. Any suggestions how to rewrite tha

Re: Building a multiline string

2010-02-04 Thread Ulrich Eckhardt
Just for the record: Neither of the below methods actually produce a multiline string. They only spread a string containing one line over multiple lines of source code. lallous wrote: > Maybe that's already documented, but it seems the parser accepts to > build a long string w/o really using the f

Re: decode(..., errors='ignore') has no effect

2010-01-12 Thread Ulrich Eckhardt
Jens Müller wrote: > I try to decode a string,e.g. > u'M\xfcnchen, pronounced [\u02c8m\u028fn\xe7\u0259n]'.decode('cp1252', > 'ignore') > but even thoug I use errors='ignore' > I get UnicodeEncodeError: 'charmap' codec can't encode character u'\u02c8' > in position 21: character maps to > > How c

Re: Endless loop

2010-01-02 Thread Ulrich Eckhardt
vsoler wrote: > class stepper: > def __getitem__(self, i): > return self.data[i] > > X=stepper() > X.data="Spam" > for item in X: > print item, > > ... what I get is S p a m which seems logical to me since the > loop stops after the 4th character. I think you're mistaking

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Ulrich Eckhardt
Peng Yu wrote: > Could somebody let me know how the python calls and exceptions are > dispatched? Is there a reference for it? I'm not a Python expert, but I have read some parts of the implementation. Hopefully someone steps up if I misrepresent things here... In order to understand Python exce

Re: IO Gurus: what are the differences between these two methods?

2009-12-08 Thread Ulrich Eckhardt
dpapathanasiou wrote: > I have two methods for writing binaries files: the first works with > data received by a server corresponding to a file upload, and the > second works with data sent as email attachments. Hmmm, no. Looking at your code, the first of your functions actually treats its argume

Re: More elegant solution for diffing two sequences

2009-12-04 Thread Ulrich Eckhardt
Lie Ryan wrote: > On 12/4/2009 8:28 AM, Ulrich Eckhardt wrote: >> I'm trying to write some code to diff two fonts. What I have is every >> character (glyph) of the two fonts in a list. I know that the list is >> sorted by the codepoints of the characters. What I'd

More elegant solution for diffing two sequences

2009-12-03 Thread Ulrich Eckhardt
Hi! I'm trying to write some code to diff two fonts. What I have is every character (glyph) of the two fonts in a list. I know that the list is sorted by the codepoints of the characters. What I'd like to ask is whether there is a more elegant solution to the loop below or whether there are any

Re: Python without wrapper script

2009-12-02 Thread Ulrich Eckhardt
eric.frederich wrote: > Is there a way to set up environment variables in python itself > without having a wrapper script. Yes, sure, you can set environment variables... > The wrapper script is now something like > > #!/bin/bash > > export LD_LIBRARY_PATH="/some/thing/lib:$LD_LIBRARY_PATH"

using struct module on a file

2009-11-18 Thread Ulrich Eckhardt
Hia! I need to read a file containing packed "binary" data. For that, I find the struct module pretty convenient. What I always need to do is reading a chunk of data from the file (either using calcsize() or a struct.Struct instance) and then parsing it with unpack(). For that, I repeatedly wri

Re: The ol' [[]] * 500 bug...

2009-11-14 Thread Ulrich Eckhardt
Diez B. Roggisch wrote: > kj schrieb: >> lol = [[] for _ in xrange(500)] > > If you call that hideous, I suggest you perform the same exercise in > Java or C++ - and then come back to python and relax I might be missing something that's not explicitly mentioned here, but I'd say that all n

Re: the unicode saga continues...

2009-11-13 Thread Ulrich Eckhardt
Ethan Furman wrote: > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print u'\xed' > í > >>> print u'\xed'.encode('cp437') > í > >>> print u'\xed'.encode('cp850') > í > >>> pr

Re: #define (from C) in Python

2009-11-13 Thread Ulrich Eckhardt
Santiago Romero wrote: > Well, In the above concrete example, that would work, but I was > talking for multiple code lines, like: > > > #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) > > #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC

Re: Python library "support" propaganda lists?

2009-10-30 Thread Ulrich Eckhardt
Aaron Watters wrote: > In the last couple months on a few occasions > I've tried various Python libraries (and I'm not going to > name names) and run into some problem. > > Following the documented procedure [...] Documented where? > [...] I eventually post the problem to the "support" list Whi

Re: Struct on on x86_64 mac os x

2009-10-21 Thread Ulrich Eckhardt
Tommy Grav wrote: > I have created a binary file that saves this struct from some C code: > >struct recOneData { > char label[3][84]; > char constName[400][6]; > double timeData[3]; > long int numConst; > double AU; > double EMRAT; > long

Re: File not closed on exception

2009-10-20 Thread Ulrich Eckhardt
arve.knud...@gmail.com wrote: > On Oct 19, 3:48 pm, Ethan Furman wrote: >> arve.knud...@gmail.com wrote: [...] >>> def create(): >>> f = file("tmp", "w") >>> raise Exception >>> >>> try: >>> create() >>> finally: >>> os.remove("tmp") >>> [...] >> When an exception is raised, the e

Re: () vs. [] operator

2009-10-15 Thread Ulrich Eckhardt
Ole Streicher wrote: > I am curious when one should implement a "__call__()" and when a > "__getitem__()" method. > > For example, I want to display functions and data in the same plot. Wait: The term 'function' is overloaded. In Python and programming in general, a function is a piece of code wi

Re: MUD Game Programmming - Python Modules in C++

2009-10-14 Thread Ulrich Eckhardt
Gabriel Genellina wrote: >> #ifdef _DEBUG >> #undef _DEBUG >> #include >> #define _DEBUG >> #else >> #include >> #endif [...to keep Python from linking against non-existant debug libraries.] > > No, don't do that. Just compile your application in release mode. Why not, does it break anything?

Re: MUD Game Programmming - Python Modules in C++

2009-10-14 Thread Ulrich Eckhardt
Christopher Lloyd wrote: > I'm a relatively inexperienced programmer, and have been learning some > basic C++ and working through the demos in Ron Penton's "MUD Game > Programming" book. In it, Python modules are run from inside a C++ > program. [...] > If I try to compile this in MS Visual C++ 200

Re: MUD Game Programmming - Python Modules in C++

2009-10-14 Thread Ulrich Eckhardt
Irmen de Jong wrote: > [...] is there any reason why you would go the route of embedding python > in C++ ? Why not just stick to (pure) Python? Embedding C or C++ stuff > as extension modules in Python (if you really need to do this) is easier > than the other way around, in my experience. If you

Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Ulrich Eckhardt
Laszlo Nagy wrote: > Ulrich Eckhardt írta: >> Hi! >> >> I'm looking at the 'threading' module and see that other than the >> 'thread' module it doesn't have a simple function to start a new thread. >> Instead, you first have to instan

Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Ulrich Eckhardt
sturlamolden wrote: > On 8 Okt, 09:17, Ulrich Eckhardt wrote: > >> I'm looking at the 'threading' module and see that other than the >> 'thread' module it doesn't have a simple function to start a new thread. >> Instead, you first have to in

No threading.start_new_thread(), useful addition?

2009-10-08 Thread Ulrich Eckhardt
Hi! I'm looking at the 'threading' module and see that other than the 'thread' module it doesn't have a simple function to start a new thread. Instead, you first have to instantiate a threading object and then start the new thread on it: t = threading.Thread(target=my_function) t.start() Wha

Re: Strange performance issue

2009-10-06 Thread Ulrich Eckhardt
Dan Stromberg wrote: > My new version formats an SD card and preallocates some file space in > about 3 minutes with "Optimize Performance" selected, and in about 30 > minutes with "Optimize for Quick Removal" selected. Needless to say, I > don't like the 27 minute penalty much. For performance, t

Re: raise errors

2009-09-21 Thread Ulrich Eckhardt
daved170 wrote: > I need help with exceptions raising. > My goal is to print at the outer functions all the errors including > the most inner one. > > For example: > > def foo1(self): >try: > foo2() >except ? : > print "outer Err at foo1" + ?? > > def foo2(self): >tr

Python history animation with code_swarm

2009-09-17 Thread Ulrich Eckhardt
Hi! Take a look at: http://vis.cs.ucdavis.edu/~ogawa/codeswarm/ code_swarm is a tool that generates a nice visual animation from a repository history. It also features one with the Python history for download, enhanced with a few comments. I hope this isn't old news and you enjoy it! Uli --

str.split() with empty separator

2009-09-15 Thread Ulrich Eckhardt
Hi! "'abc'.split('')" gives me a "ValueError: empty separator". However, "''.join(['a', 'b', 'c'])" gives me "'abc'". Why this asymmetry? I was under the impression that the two would be complementary. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -

Re: Why can't I run this test class?

2009-09-11 Thread Ulrich Eckhardt
Kermit Mei wrote: > #!/usr/bin/env > python > > class Test: > 'My Test class' > def __init__(self): > self.arg1 = 1 > > def first(self): > return self.arg1 > > t1 = Test 't1' is now an alternative name for 'Test'. What you wanted instead was to instantiate 'Test', wh

Re: using python interpreters per thread in C++ program

2009-09-07 Thread Ulrich Eckhardt
ganesh wrote: >> Did you remeber to acquire the GIL? The GIL is global to the process > > No, I did not use GIL. > > -- Why do we need to use GIL even though python is private to each > thread? Quoting from above: "The GIL is global to the process". So no, it is NOT private to each thread which

Re: The future of Python immutability

2009-09-04 Thread Ulrich Eckhardt
Nigel Rantor wrote: > John Nagle wrote: >> Immutability is interesting for threaded programs, because >> immutable objects can be shared without risk. Consider a programming >> model where objects shared between threads must be either immutable or >> "synchronized" in the sense that Java uses

Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
kj wrote: > class Demo(object): > def fact_iter(n): > ret = 1 > for i in range(1, n + 1): > ret *= i > return ret > > def fact_rec(n): > if n < 2: > return 1 > else: > return n * fact_rec(n - 1) > > classvar1

Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: > Jean-Michel Pichavant wrote: >> class Color: >> def __init__(self, r, g,b): >> pass >> BLACK = Color(0,0,0) >> >> It make sens from a design point of view to put BLACK in the Color >> namespace. But I don&

Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
Jean-Michel Pichavant wrote: > class Color: > def __init__(self, r, g,b): > pass > BLACK = Color(0,0,0) > > It make sens from a design point of view to put BLACK in the Color > namespace. But I don't think it's possible with python. class Color: ... setattrib(Color, "BLACK"

With or without leading underscore...

2009-08-10 Thread Ulrich Eckhardt
...that is the question! I have a module which exports a type. It also exports a function that returns instances of that type. Now, the reason for my question is that while users will directly use instances of the type, they will not create instances of the type themselves. So, the type is a part

Re: Problem Regarding Handling of Unicode string

2009-08-10 Thread Ulrich Eckhardt
joy99 wrote: > [...] it is giving me output like: > '\xef\xbb\xbf\xe0\xa6\x85\xe0\xa6\xa8\xe0\xa7\x87\xe0\xa6\x95' These three bytes encode the byte-order marker (BOM, Unicode uFEFF) as UTF-8, followed by codepoint u09a8 (look it up on unicode.org what that is). In any case, if th

Re: C-API, tp_dictoffset vs tp_members

2009-07-26 Thread Ulrich Eckhardt
"Martin v. Löwis" wrote: I have a predefined set of members, some of which are optional. >>> Having optional fields is also a good reason. >> >> What is the use of T_OBJECT_EX vs T_OBJECT in PyMemberDef then? > > Right - this works for optional objects. However, it can't possibly > work for

Re: Removing newlines from string on windows (without replacing)

2009-07-26 Thread Ulrich Eckhardt
Tom wrote: > s = sauce.replace("\n", "") > > Sauce is a string, read from a file, that I need to remove newlines > from. This code works fine in Linux, but not in Windows. rstrip("\n") > won't work for me, so anybody know how to get this working on Windows? I'm pretty sure this works regardless o

Re: C-API, tp_dictoffset vs tp_members

2009-07-26 Thread Ulrich Eckhardt
"Martin v. Löwis" wrote: >> I have a predefined set of members, some of which are optional. > > Having optional fields is also a good reason. What is the use of T_OBJECT_EX vs T_OBJECT in PyMemberDef then? I would have though that the former describes an optional field, because the behaviour of

Re: binary literal

2009-07-22 Thread Ulrich Eckhardt
superpollo wrote: > i can insert a hex value for a character literal in a string: > > >>> stuff = "\x45" > >>> print stuff > E > >>> > > can i do something like the above, but using a *binary* number? (e.g. > 00101101 instead of 45) ? There are binary number literals since 2.6 and there is th

C-API, tp_dictoffset vs tp_members

2009-07-20 Thread Ulrich Eckhardt
Hi! When would I use PyObject_SetAttrString/tp_dictoffset instead of tp_members? I have a predefined set of members, some of which are optional. The problem I had with an embedded dictionary was that I can't see its elements using "dir()". Now I just converted to using tp_members, and it still

Re: allowing output of code that is unittested?

2009-07-16 Thread Ulrich Eckhardt
per wrote: > i am using the standard unittest module to unit test my code. my code > contains several print statements which i noticed are repressed when i > call my unit tests using: > > if __name__ == '__main__': > suite = unittest.TestLoader().loadTestsFromTestCase(TestMyCode) > unittes

Re: simple question about Dictionary type containing List objects

2009-07-13 Thread Ulrich Eckhardt
gganesh wrote: > I have a dict object like > emails={'mycontacts': [ 'x...@gmail.com, 'y...@gmail.com', > 'z...@gmail.com'], 'myname':['gganesh']} > I need to get the lenght of the list mycontacts ,like > mycontacts_numbers=3 mycontacts = emails['mycontacts'] mycontacts_number = len(mycontacts) A

Fractions as result from divisions (was: Re: tough-to-explain Python)

2009-07-08 Thread Ulrich Eckhardt
Bearophile wrote: > For example a novice wants to see 124 / 38 to return the 62/19 > fraction and not 3 or 3.263157894736842 :-) Python has adopted the latter of the three for operator / and the the second one for operator //. I wonder if it was considered to just return a fraction from that opera

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-03 Thread Ulrich Eckhardt
Thanks to all that answered, in particular I wasn't aware of the existence of the __del__ function. For completeness' sake, I think I have found another way to not really solve but at least circumvent the problem: weak references. If I understand correctly, those would allow me to pass out handles

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread Ulrich Eckhardt
Bearophile wrote: > Ulrich Eckhardt: >> a way to automatically release the resource, something >> which I would do in the destructor in C++. > > Is this helpful? > http://effbot.org/pyref/with.htm Yes, it aims in the same direction. However, I'm not sure this app

Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread Ulrich Eckhardt
Hi! I'm currently converting my bioware to handle Python code and I have stumbled across a problem... Simple scenario: I have a handle to a resource. This handle allows me to manipulate the resource in various ways and it also represents ownership. Now, when I put this into a class, instances to

Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Ulrich Eckhardt
Robert Kern wrote: > I wish people would stop representing decimal floating point arithmetic as > "more accurate" than binary floating point arithmetic. Those that failed, learned. You only see those that haven't learnt yet. Dialog between two teachers: T1: Oh those pupils, I told them hundred ti

Re: How to convert he boolean values into integers

2009-06-25 Thread Ulrich Eckhardt
krishna wrote: > I need to convert 1010100110 boolean value to some think like 2345, if > its possible then post me your comment on this Yes, sure. You can simply sum up the digit values and then format them as decimal number. You can also just look up the number: def decode_binary(input):

Re: Can I replace this for loop with a join?

2009-06-22 Thread Ulrich Eckhardt
Ben Finney wrote: > Paul Watson writes: >> On Mon, 2009-04-13 at 17:03 +0200, WP wrote: >> > dict = {1:'astring', 2:'anotherstring'} >> > for key in dict.keys(): >> > print 'Press %i for %s' % (key, dict[key]) >> >> In addition to the comments already made, this code will be quite >> broken

Re: : an integer is required

2009-06-16 Thread Ulrich Eckhardt
Dave Angel wrote: > Ulrich Eckhardt wrote: >> open() doesn't take a string as second parameter, see 'help(open)'. >> Instead, it takes one of the integers which are defined as symbols in the >> os module, see 'dir(os)'. > > [...]The second

Re: : an integer is required

2009-06-15 Thread Ulrich Eckhardt
jeni wrote: [ ..large backtrace.. ] For your own sake and that of your readers, try next time to reduce the code that causes the problems to a minimal example. This prevents people from guessing or simply ignoring your problems. > /home/Activities/Kremala.activity/Kremala.py in insert_text_file >

Re: Impossible to reinstall python-opensync which made unusable my package installation tools

2009-06-15 Thread Ulrich Eckhardt
Cassian Braconnier wrote: > [...] completely broke Synaptic, and made it impossible to install any > (other, non python) package with apt-get or dpkg commands. This is not a Python error and it doesn't actually belong here. > So far I could not get any useful advice on the french ubuntu users > f

Re: Convert integer to fixed length binary string

2009-06-11 Thread Ulrich Eckhardt
casebash wrote: > I know the bin function converts an int into a binary string. Binary string sounds ambiguous. Firstly, everything is binary. Secondly, strings are byte strings or Unicode strings. In any case, I'm not 100% sure what you mean - giving an example of input and output would help! >

retrieve bitwise float representation

2009-06-10 Thread Ulrich Eckhardt
Hi! I need to pack a floating point value into a vector of 32-bit unsigned values in IEEE format. Further, I maintain a CRC32 checksum for integrity checking. For the latter, I actually need the float as integral value. What I currently do is this: tmp = struct.pack("=f", f) (i,) = struct.un

Re: os.path.split gets confused with combined \\ and /

2009-05-18 Thread Ulrich Eckhardt
Stef Mientki wrote: > I've to distribute both python files and data files. > Everything is developed under windows and now the datafiles contains > paths with mixed \\ and /. For your info: Some (!!!) parts of MS Windows understand forward slashes as path separators and disallows them in file name

Re: How to convert a list of strings to a tuple of floats?

2009-05-18 Thread Ulrich Eckhardt
boblat...@googlemail.com wrote: > this is the conversion I'm looking for: > > ['1.1', '2.2', '3.3'] -> (1.1, 2.2, 3.3) > > Currently I'm "disassembling" the list by hand, like this: > > fields = line.split('; ') > for x in range(len(fields)): > fields[x] = float(fields[x]) >

Re: Seeking old post on developers who like IDEs vs developers who like simple languages

2009-05-18 Thread Ulrich Eckhardt
Steve Ferg wrote: > On the one hand, there are developers who love big IDEs with lots of > features (code generation, error checking, etc.), and rely on them to > provide the high level of support needed to be reasonably productive > in heavy-weight languages (e.g. Java). > > On the other hand the

Re: OOP & Abstract Classes

2009-05-11 Thread Ulrich Eckhardt
Adam Gaskins wrote: > Long story short, I'm tired of doing things in such a hackish manner > and want to write applications that are cross platform (I'd like to > get our production dept on linux eventually) and truely object > oriented. Adam, there is one notion here that I seriously dislike: yo

Skipping unit tests

2009-05-11 Thread Ulrich Eckhardt
Hi! We have a few tests for some module here. These tests are under development and applied to older versions (with less features) of the module, too. That means that if I have module version 42, tests A and B can not possibly work. I don't want to have test failures but I also don't want to fork

Re: Convert variable directly into a string (no ASCII)

2009-05-02 Thread Ulrich Eckhardt
Justin Rajewski wrote: > I need to print variables out over serial, however I need them to not be > in ASCII, ie if the variable is 5 then print 5 not "5". > > The function that writes to the serial port requires a string and I can > send non-variables out with the string "/x05" for 5. Take a loo

Re: if statement, with function inside it: if (t = Test()) == True:

2009-04-24 Thread Ulrich Eckhardt
Steven D'Aprano wrote: > On Fri, 24 Apr 2009 03:00:26 -0700, GC-Martijn wrote: >> t = Test() >> if (t == 'Vla': >> print t # must contain Vla > > > What's wrong with that? It unnecessarily injects the name 't' into the scope. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amts

Re: Unicode in writing to a file

2009-04-23 Thread Ulrich Eckhardt
Carbon Man wrote: > self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) > cValue contains a unicode character. node.tagName is also a unicode string > though it has no special characters in it. > Getting the error: > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in >

Re: Supply a plugin interface

2009-04-23 Thread Ulrich Eckhardt
Johannes Bauer wrote: > What I'd like to add: I want the GUI users to supply plugin scripts, > i.e. offer some kind of API. That is, I want the user to write short > Python pieces which look something like > > import guiapp > > class myplugin(): > def __init__(self): > guiapp.add_menu("foobar") >

Re: Equivalent to C bitmasks and enumerations

2009-04-20 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: [how to handle bitfields and enumerations in Python] Thanks to all that answered. The important lessons I learned: * You can modify classes, other than in C++ where they are statically defined. This allows e.g. adding constants. * __repr__ should provide output suitable

Equivalent to C bitmasks and enumerations

2009-04-15 Thread Ulrich Eckhardt
Greetings! I'm currently using Python to implement a set of tests for code that is otherwise written in C. This code was wrapped using Boost.Python and is then loaded into Python as module. What I often have in C is this: // bitfield (several flags combined) #define STATUS_OVERTEMP 1u #def

Re: Why does Python show the whole array?

2009-04-08 Thread Ulrich Eckhardt
Gilles Ganault wrote: > test = "t...@gmail.com" > isp = ["gmail.com", "yahoo.com"] > for item in isp: > if test.find(item): > print item > === output > gmail.com > yahoo.com > === > > Any idea why I'm also getting "yahoo.com"? find() returns the index where it is found or -1 if it is not

Re: building release - assert-free python library

2009-04-07 Thread Ulrich Eckhardt
grbgooglefan wrote: > How can I build a release and not the debug version of libpython.a? > I have seen that there are assert, abort statements in lot many > functions in Python code. I would like to avoid those when compiling > the libpython.a library because when this libpython gets used for > pr

Re: integrate does not work anymore

2009-03-25 Thread Ulrich Eckhardt
Doerte wrote: > from pylab import * > from numpy import * > from scipy import * > from math import * Don't do this, read the style guide on writing Python code. > res = integrate.quad(func=f, a=x0, b=x1) [...] > NameError: name 'integrate' is not defined # try this instead from scipy import inte

Re: How to do this in Python?

2009-03-18 Thread Ulrich Eckhardt
Grant Edwards wrote: > with open(filename,"rb") as f: > while True: > buf = f.read(1) > if not buf: break > # do something The pattern with foo() as bar: # do something with bar is equivalent to bar = foo() if bar: # do something with bar except

Re: String to sequence

2009-03-14 Thread Ulrich Eckhardt
mattia wrote: > How can I convert the following string: > > 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', > EGC','SXF','BZR','BIQ','BLL','BHX','BLQ' > > into this sequence: > > ['AAR','ABZ','AGA','AHO','ALC','LEI','AOC', > EGC','SXF','BZR','BIQ','BLL','BHX','BLQ'] import string string.split("a,b,c

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-12 Thread Ulrich Eckhardt
Raymond Hettinger wrote: >> The idea is to make numbering formatting a little easier with >> the new format() builtin: >> http://docs.python.org/library/string.html#formatspec [...] > Scanning the web, I've found that thousands separators are > usually one of COMMA, PERIOD, SPACE, or UNDERSCORE. T

Re: starting a Python 2.5 executable without the DOS window

2009-02-27 Thread Ulrich Eckhardt
Greg Miller wrote: > I would like to know if there is a way of starting the GUI > without the DOS window having to launch? Use pythonw.exe instead of python.exe. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinf

struct.unpack() on a stream

2009-02-27 Thread Ulrich Eckhardt
Hi! I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack() stops complaining about a lack of data, but that sounds rather inelegant. Any better suggestions? Uli -- Sator Laser GmbH Geschäftsführer: Tho

Re: Too many open files

2009-02-09 Thread Ulrich Eckhardt
psaff...@googlemail.com wrote: > I'm building a pipeline involving a number of shell tools. In each > case, I create a temporary file using tempfile.mkstmp() and invoke a > command ("cmd < /tmp/tmpfile") on it using subprocess.Popen. > > At the end of each section, I call close() on the file handl

Re: Python 3.0 slow file IO

2009-02-05 Thread Ulrich Eckhardt
thomasvang...@gmail.com wrote: > C:\python30> patch -p0 < fileio_buffer.patch > The patch command is not recognized.. You need the 'patch' program first. Further, you will need a C compiler. If you don't know how to compile from sources, I would postpone patching sources to after learning that. >

<    1   2   3   4   5   >