Re: data attributes override method attributes?

2012-09-25 Thread Ulrich Eckhardt
Am 25.09.2012 16:11, schrieb alex23: On Sep 26, 12:08 am, Peter Otten __pete...@web.de wrote: Jayden wrote: In the Python Tutorial, Section 9.4, it is said that Data attributes override method attributes with the same name. The tutorial is wrong here. That should be Instance attributes

Re: Functional way to compare things inside a list

2012-09-21 Thread Ulrich Eckhardt
Am 21.09.2012 00:58, schrieb thorso...@lavabit.com: list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] I want to check for a value (e.g. '4'), and get the key of the dictionary that contains that value. Note: 1. list is a built-in type, who's name is rebound above 2. The list above contains

Re: Decorators not worth the effort

2012-09-14 Thread Ulrich Eckhardt
Am 14.09.2012 11:28, schrieb Jean-Michel Pichavant: Decorators are very popular so I kinda already know that the fault is mine. Now to the reason why I have troubles writing them, I don't know. Every time I did use decorators, I spent way too much time writing it (and debugging it). I wrote the

Re: python2.7 lack necessary bit to build module

2012-09-13 Thread Ulrich Eckhardt
Am 13.09.2012 10:47, schrieb 钟驰宇: I'm in ubuntu10.04 and I decide to compile python2.7 from source [...] However when I run my GAE app,it comes out with no module named _ssl and _sqlite3. There are Debian-specific ways to ease this task that should work in Ubuntu, too. First is apt-get

Re: main and dependent objects

2012-09-13 Thread Ulrich Eckhardt
Am 13.09.2012 14:51, schrieb andrea crotti: I am in a situation where I have a class Obj which contains many attributes, and also contains logically another object of class Dependent. This dependent_object, however, also needs to access many fields of the original class, so at the moment we did

Re: Accessing dll

2012-09-06 Thread Ulrich Eckhardt
Am 06.09.2012 17:07, schrieb Helpful person: I am a complete novice to Python. Welcome! I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll

Re: How to program test(expr) ?

2012-08-30 Thread Ulrich Eckhardt
Am 29.08.2012 17:04, schrieb Franck Ditter: I use Python 3.2.3 + Idle. Is it possible to program test(e) which takes an expression e and whose execution produces at the toplevel an echo of e and the effects and result of its evaluation ? Yes, the key to this is using a lambda expression. #

Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Ulrich Eckhardt
Am 30.08.2012 12:55, schrieb 陈伟: class A(object): d = 'it is a doc.' t = A() print t.__class__.d print t.d the output is same. You could go even further: print id(t.__class__.d) print id(t.d) which should show you that they are not just equal but identical. so it means class

Re: Beginners question

2012-08-30 Thread Ulrich Eckhardt
Am 30.08.2012 13:54, schrieb boltar2003@boltar.world: s = os.stat(.) print s posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st _ctime=1346327754) What sort of object is

Re: Beginners question

2012-08-30 Thread Ulrich Eckhardt
Am 30.08.2012 15:27, schrieb Marco Nawijn: On Thursday, August 30, 2012 3:15:03 PM UTC+2, Ulrich Eckhardt wrote: Am 30.08.2012 13:54, schrieb boltar2003@boltar.world: What sort of object is posix.stat_result? [...] I guess that this is a named tuple, which is a tuple where the attributes

Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread Ulrich Eckhardt
Am 27.08.2012 03:23, schrieb bruceg113...@gmail.com: My program uses Python 2.6 and Sqlite3 and connects to a network database 100 miles away. Wait, isn't SQLite completely file-based? In that case, SQLite accesses a file, which in turn is stored on a remote filesystem. This means that there

Re: color coding for numbers

2012-08-22 Thread Ulrich Eckhardt
Am 21.08.2012 19:07, schrieb DJC: On 21/08/12 12:55, Ulrich Eckhardt wrote: Am 21.08.2012 10:38, schrieb namenobodywa...@gmail.com: what is the best way Define best before asking such questions. ;) http://matplotlib.sourceforge.net/api/colors_api.html?highlight=colors#matplotlib.colors

Re: Top-posting c.

2012-08-21 Thread Ulrich Eckhardt
Am 21.08.2012 00:49, schrieb Prasad, Ramit: I also tend to blame M$ (Outlook and variants) for this tendency to quote everything and top-post -- Outlook makes it almost impossible to do a triminterleave response style. I [think] that Outlook Co are guilty. That and the fact that few people

Re: color coding for numbers

2012-08-21 Thread Ulrich Eckhardt
Am 21.08.2012 10:38, schrieb namenobodywa...@gmail.com: what is the best way Define best before asking such questions. ;) using color/shading on a tkinter canvas as a visualization for a two-dimensional grid of numbers? so far my best idea is to use the same value for R,G and B (fill =

Re: Top-posting c.

2012-08-17 Thread Ulrich Eckhardt
I that Outlook Co are guilty. That and the fact that few people even think about this. Even today that makes sense, because it provides an exact context. Without that, you wouldn't be able to really understand what exactly a person is referring to. Also, it helps people to structure their

Re: set and dict iteration

2012-08-17 Thread Ulrich Eckhardt
Am 17.08.2012 03:01, schrieb Paul Rubin: Ian Kelly ian.g.ke...@gmail.com writes: With regard to key insertion and deletion while iterating over a dict or set, though, there is just no good reason to be doing that (especially as the result is very implementation-specific), and I wouldn't mind a

Re: Installing Python 3.2.3 on Win 7

2012-08-16 Thread Ulrich Eckhardt
Am 16.08.2012 09:17, schrieb Johan van Zyl: I installed Python 3.2.3 successfully on my work laptop (XP) but cannot seem to do it on my home PC (Win7) I click the button to install and the window just disappears o the screen. So how do I in fact install Python 3.2.3 on Win 7? I used some MSI

Re: Threads and sockets

2012-08-13 Thread Ulrich Eckhardt
Am 10.08.2012 15:01, schrieb loial: I am writing an application to send data to a printer port(9100) and then recieve PJL responses back on that port. Because of the way PJL works I have to do both in the same process(script). If I understand that right, you are opening a TCP connection, so

Re: On-topic: alternate Python implementations

2012-08-08 Thread Ulrich Eckhardt
Am 04.08.2012 15:53, schrieb Stefan Behnel: So, if a C++ compiler takes a .c file and compiles it with C language semantics, it doesn't qualify as a C compiler? That implies a rather weird definition of a C compiler, I'd say. I'd say that even a brainfuck compiler compiling a .py file with C

Re: Calling Values

2012-08-03 Thread Ulrich Eckhardt
Am 03.08.2012 13:49, schrieb Subhabrata: I am trying to call the values of one function in the another function in the following way: def func1(): num1=10 num2=20 print The Second Number is:,num2 return def func2(): num3=num1+num2

Re: CRC-checksum failed in gzip

2012-08-02 Thread Ulrich Eckhardt
Am 01.08.2012 19:57, schrieb Laszlo Nagy: ## Open file lock = threading.Lock() fin = gzip.open(file_path...) # Now you can share the file object between threads. # and do this inside any thread: ## data needed. block until the file object becomes usable. with lock: data = fin.read() #

consistent input() for Python 2 and 3

2012-08-02 Thread Ulrich Eckhardt
Hi! I'm trying to write some code that should work with both Python 2 and 3. One of the problems there is that the input() function has different meanings, I just need the raw_input() behaviour of Python 2. My approach is to simply do this: try: # redirect input() to raw_input()

NameError vs AttributeError

2012-07-31 Thread Ulrich Eckhardt
Hi! Using Python 2.7, I stumbled across the fact that 'self.xy' raises an AttributeError if self doesn't have an 'xy' as attribute, but 'xy' will instead raise a NameError. To some extent, these two are very similar, namely that the name 'xy' couldn't be resolved in a certain context, but

Re: Extracting bit fields from an IEEE-784 float

2012-07-30 Thread Ulrich Eckhardt
Am 30.07.2012 02:44, schrieb Steven D'Aprano: I wish to extract the bit fields from a Python float, call it x. First I cast the float to 8-bytes: s = struct.pack('=d', x) i = struct.unpack('=q', s)[0] Then I extract the bit fields from the int, e.g. to grab the sign bit: (i

Re: from future import pass_function

2012-07-27 Thread Ulrich Eckhardt
Am 26.07.2012 09:50, schrieb Mark Lawrence: And if we could persuade the BDFL to introduce braces, we could have {() and }() What do you mean persuade? Braces work perfectly: def foo(): {} grin, duck and run faster as the impacts get closer Uli --

Re: from future import pass_function

2012-07-26 Thread Ulrich Eckhardt
Am 25.07.2012 18:05, schrieb Chris Angelico: By comparison, Python 2's print statement is executable. It causes real action to happen at run-time. It makes sense to pass print as an argument to something; for instance: def some_generator(): yield blah map(print,some_generator()) Simple

Re: from future import pass_function

2012-07-26 Thread Ulrich Eckhardt
Am 26.07.2012 04:38, schrieb Steven D'Aprano: The examples of pass-as-a-function shown by the Original Poster don't give any clue of what advantage there is to make pass a function. Just read the text, it just struck me how similar pass and print are, i.e. that neither actually needs to be a

Re: from future import pass_function

2012-07-26 Thread Ulrich Eckhardt
Am 26.07.2012 07:20, schrieb Michael Hrivnak: If we want pass(), then why not break() and continue()? And also def() and class()? for(), while(), if(), with(), we can make them all callable objects! Except that they are control statements. They are not objects, they have no type, and they

Re: from future import pass_function

2012-07-26 Thread Ulrich Eckhardt
Am 26.07.2012 11:26, schrieb Steven D'Aprano: On Thu, 26 Jul 2012 08:59:30 +0200, Ulrich Eckhardt wrote: Am 26.07.2012 04:38, schrieb Steven D'Aprano: (Actually, I reckon that what is driving this idea is that the OP is a beginner, and he's got a syntax error a few times from writing pass

Re: Python 2.6 StreamReader.readline()

2012-07-25 Thread Ulrich Eckhardt
Am 24.07.2012 17:01, schrieb cpppw...@gmail.com: reader = codecs.getreader(encoding) lines = [] with open(filename, 'rb') as f: lines = reader(f, 'strict').readlines(keepends=False) where encoding == 'utf-16-be' Everything works fine, except that lines[0] is equal to

from future import pass_function

2012-07-25 Thread Ulrich Eckhardt
Hi! I just had an idea, it occurred to me that the pass statement is pretty similar to the print statement, and similarly to the print() function, there could be a pass() function that does and returns nothing. Example: def pass(): return try: do_something() except:

Re: What's wrong with this code?

2012-07-24 Thread Ulrich Eckhardt
There is one model that has helped me much understanding how Python ticks and that is the model of name tags. The code a = 1 creates an integer with value 1 and attaches a tag with a written on it using a small piece of rope. Now, if you attach the tag to a different item, it obviously doesn't

Re: What's wrong with this code?

2012-07-24 Thread Ulrich Eckhardt
Am 24.07.2012 10:24, schrieb Chris Angelico: On Tue, Jul 24, 2012 at 5:47 PM, Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote: There is one model that has helped me much understanding how Python ticks and that is the model of name tags. The code a = 1 creates an integer with value 1

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Ulrich Eckhardt
Am 18.07.2012 11:06, schrieb Lipska the Kat: On 18/07/12 01:46, Andrew Cooper wrote: Take for example a Linux system call handler. The general form looks a little like (substituting C for python style pseudocode) if not (you are permitted to do this): return -EPERM if not (you've given

Re: Encapsulation, inheritance and polymorphism

2012-07-17 Thread Ulrich Eckhardt
Welcome! Am 17.07.2012 10:45, schrieb Lipska the Kat: I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. In addition to this forum for direct help and discussion, two suggestions: Firstly, it could help if you

Re: assertraises behaviour

2012-07-17 Thread Ulrich Eckhardt
Am 17.07.2012 11:06, schrieb andrea crotti: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also

Re: Encapsulation, inheritance and polymorphism

2012-07-17 Thread Ulrich Eckhardt
Am 17.07.2012 13:01, schrieb Lipska the Kat: On 17/07/12 10:30, Ulrich Eckhardt wrote: Am 17.07.2012 10:45, schrieb Lipska the Kat: I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. In addition to this forum

Re: Diagramming code

2012-07-16 Thread Ulrich Eckhardt
Am 16.07.2012 03:57, schrieb hamilton: OK then, let me ask, how do you guys learn/understand large projects ? 1. Use the program. This gives you an idea what features are there and a bit how it could be structured. 2. Build the program, to see what is done to get the program running. This

Re: Mocked object returning another Mocked object

2012-07-13 Thread Ulrich Eckhardt
Am 13.07.2012 12:09, schrieb Jean-Michel Pichavant: I have an App object with the 'target' attribute. This target is controlling a piece of hardware. The hardware itself holds a software, hence the target object having an 'api' attribute. I hope I make sense. So basically I'd like

Re: post init call

2012-06-18 Thread Ulrich Eckhardt
Am 18.06.2012 09:10, schrieb Prashant: class Shape(object): def __init__(self, shapename): self.shapename = shapename def update(self): print update class ColoredShape(Shape): def __init__(self, color): Shape.__init__(self, color)

Re: Py3.3 unicode literal and input()

2012-06-18 Thread Ulrich Eckhardt
Am 18.06.2012 16:00, schrieb jmfauth: A string is a string, a piece of text, period. No. There are different representations for the same piece of text even in the context of just Python. b'fou', u'fou', 'fou' are three different source code representations, resulting in two different runtime

Re: Why does this leak memory?

2012-06-11 Thread Ulrich Eckhardt
Am 08.06.2012 18:02, schrieb Steve: Well, I guess I was confused by the terminology. I thought there were leaked objects _after_ a garbage collection had been run (as it said collecting generation 2). Also, unreachable actually appears to mean unreferenced. You live n learn... Actually I

Re: English version for Mémento Python 3 (draft, readers needed)

2012-06-06 Thread Ulrich Eckhardt
Am 05.06.2012 19:32, schrieb Laurent Pointal: I started a first translation of my document originally in french. Could some fluent english people read it and indicate errors or bad english expressions. Just one note up front: Languages or nationalities are written with uppercase letters,

Re: fputs

2012-06-05 Thread Ulrich Eckhardt
Am 05.06.2012 15:54, schrieb hassan: what is the equivalent to the php fputs in python If that fputs() is the same as C's fputs(), then write() is pretty similar. Check the documentation for files, you will surely find the equivalent. Uli --

Re: How to suppress exception printing to console?

2012-06-01 Thread Ulrich Eckhardt
Am 01.06.2012 05:06, schrieb Qi: On 2012-5-31 23:01, Ulrich Eckhardt wrote: I can only guess what you are doing, maybe you should provide a simple piece of code (or, rather, one C++ piece and a Python piece) that demonstrates the issue. What I could imagine is that the Python interpreter

Re: How to suppress exception printing to console?

2012-05-31 Thread Ulrich Eckhardt
Am 31.05.2012 09:57, schrieb Qi: I have an application that embedding Python into C++. When any exception occurred in C++ code, PyErr_SetString will be called to propagate the exception to Python. The first sentence is clear. The second sentence rather sounds as if you were implementing a

Re: Python 2.7.3, C++ embed memory leak?

2012-05-29 Thread Ulrich Eckhardt
Am 29.05.2012 16:37, schrieb Qi: I tried to only call Py_Initialize() and Py_Finalize(), nothing else between those functions, Valgrind still reports memory leaks on Ubuntu? Call the pair of functions twice, if the reported memory leak doesn't increase, there is no problem. I personally

installing 2 and 3 alongside on MS Windows

2012-05-25 Thread Ulrich Eckhardt
Hi! I'm using Python 2.7 for mostly unit testing here. I'm using Boost.Python to wrap C++ code into a module, in another place I'm also embedding Python as interpreter into a test framework. This is the stuff that must work, it's important for production use. I'm running MS Windows XP here and

Re: Python Book for a C Programmer?

2012-05-24 Thread Ulrich Eckhardt
Am 24.05.2012 01:45, schrieb hsa...@gmail.com: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? First thing to check first is

Re: Korean fonts on Python 2.6 (MacOsX)

2012-05-24 Thread Ulrich Eckhardt
Am 23.05.2012 11:30, schrieb 20_feet_tall: I have a problem with the visualization of korean fonts on Python. When I try to type in the characters only squares come out. I have tried to install the CJK codec, the hangul 1.0 codec but still no result. What exactly do you mean with

Re: Difference between str.isdigit() and str.isdecimal() in Python 3

2012-05-16 Thread Ulrich Eckhardt
Marco wrote: '123'.isdecimal(), '123'.isdigit() (True, True) print('\u0660123') ٠123 '\u0660123'.isdigit(), '\u0660123'.isdecimal() (True, True) print('\u216B') Ⅻ '\u216B'.isdecimal(), '\u216B'.isdigit() (False, False) [chr(a) for a in range(0x2) if chr(a).isdigit()]

Re: How to get outer class name from an inner class?

2012-05-09 Thread Ulrich Eckhardt
Am 08.05.2012 22:05, schrieb John Gordon: [...] class QuestionTooShortError(ApplicationException): User entered a security question which is too short. pass class QuestionTooLongError(ApplicationException): User entered a security question which is too long. pass This

Re: Question of Python second loop break and indexes

2012-05-09 Thread Ulrich Eckhardt
Am 09.05.2012 10:36, schrieb lilin Yi: //final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the

docstrings for data fields

2012-05-03 Thread Ulrich Eckhardt
Hi! My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with functions I would simply add a docstring explaining the meaning of this, but how do I do that for a non-function member? Note also that ideally, this constant wouldn't show up inside instances of the class but only inside

Re: functions which take functions

2012-04-10 Thread Ulrich Eckhardt
Am 09.04.2012 20:57, schrieb Kiuhnm: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Take a look at decorators, they not only take non-trivial functions but also return them. That

Re: tabs/spaces

2012-04-02 Thread Ulrich Eckhardt
Am 30.03.2012 14:47, schrieb Dave Angel: But since it doesn't do it on all messages, have you also confirmed that it does it for a text message? My experience seems to be that only the html messages are messed up that way. I can't find any HTML in what I posted, so HTML is not the problem. A

Re: tabs/spaces

2012-03-30 Thread Ulrich Eckhardt
Am 29.03.2012 17:25, schrieb Terry Reedy: I am using Thunderbird, win64, as news client for gmane. The post looked fine as originally received. The indents only disappeared when I hit reply and the s were added. I can confirm this misbehaviour of Thunderbird (version 11.0 here), it strips the

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:07, schrieb Steven D'Aprano: First off, that is not Python code. catch Exception gives a syntax error. Old C++ habits... :| Secondly, that is not the right way to do this unit test. You are testing two distinct things, so you should write it as two separate tests:

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:26, schrieb Terry Reedy: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: with self.assertRaises(MyException(SOME_FOO_ERROR)): foo() I presume that if this worked the way you want, all attributes would have to match. The message part of builtin exceptions is allowed to change

tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type)

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:26, schrieb Terry Reedy: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: [...] # call testee and verify results try: ...call function here... except exception_type as e: if not exception is None: self.assertEqual(e, exception) Did you use tabs? They do not get preserved

unittest: assertRaises() with an instance instead of a type

2012-03-28 Thread Ulrich Eckhardt
Hi! I'm currently writing some tests for the error handling of some code. In this scenario, I must make sure that both the correct exception is raised and that the contained error code is correct: try: foo() self.fail('exception not raised') catch MyException as e:

Re: Enchancement suggestion for argparse: intuit type from default

2012-03-14 Thread Ulrich Eckhardt
Am 13.03.2012 22:08, schrieb Roy Smith: Using argparse, if I write: parser.add_argument('--foo', default=100) it seems like it should be able to intuit that the type of foo should be int (i.e. type(default)) without my having to write: parser.add_argument('--foo', type=int,

building GNU debugger (was: Re: Python-list Digest, Vol 101, Issue 164)

2012-02-29 Thread Ulrich Eckhardt
Three things up front: 1. Do not reply to digests. If you want to only read, you can use the digests, but they are not usable for replying, because it is completely unclear where in a discussion you are entering and what you are relating your answers to. 2. Do not start new threads by using the

Re: format a measurement result and its error in scientific way

2012-02-17 Thread Ulrich Eckhardt
Am 16.02.2012 01:18, schrieb Daniel Fetchinson: Hi folks, often times in science one expresses a value (say 1.03789291) and its error (say 0.00089) in a short way by parentheses like so: 1.0379(9) Just so that I understand you, the value of the last digit is somewhere between 9-9 and 9+9,

Re: Automatic Type Conversion to String

2012-02-14 Thread Ulrich Eckhardt
Am 14.02.2012 00:18, schrieb Bruce Eckel: I'm willing to subclass str, but when I tried it before it became a little confusing -- I think mostly because anytime I assigned to self it seemed like it converted the whole object to a str rather than a Path. I suspect I don't know the proper idiom

Re: name of a sorting algorithm

2012-02-14 Thread Ulrich Eckhardt
Am 14.02.2012 16:01, schrieb Jabba Laci: Could someone please tell me what the following sorting algorithm is called? Let an array contain the elements a_1, a_2, ..., a_N. Then: for i = 1 to N-1: for j = i+1 to N: if a_j a_i then swap(a_j, a_i) It's so simple that it's not

Re: difference between random module in python 2.6 and 3.2?

2012-02-07 Thread Ulrich Eckhardt
Am 06.02.2012 09:45, schrieb Matej Cepl: Also, how could I write a re-implementation of random.choice which would work same on python 2.6 and python 3.2? It is not only matter of unit tests, but I would really welcome if the results on both versions produce the same results. Two approaches

Re: xhtml encoding question

2012-02-02 Thread Ulrich Eckhardt
Am 02.02.2012 12:02, schrieb Peter Otten: Ulrich Eckhardt wrote: u'abc'.translate({u'a': u'A'}) u'abc' I would call this a chance to improve Python. According to the documentation, using a string [as key] is invalid, but it neither raises an exception nor does it do the obvious and accept

Re: xhtml encoding question

2012-02-01 Thread Ulrich Eckhardt
Am 31.01.2012 19:09, schrieb Tim Arnold: high_chars = { 0x2014:'mdash;', # 'EM DASH', 0x2013:'ndash;', # 'EN DASH', 0x0160:'Scaron;',# 'LATIN CAPITAL LETTER S WITH CARON', 0x201d:'rdquo;', # 'RIGHT DOUBLE QUOTATION MARK', 0x201c:'ldquo;', # 'LEFT DOUBLE QUOTATION MARK',

Re: xhtml encoding question

2012-02-01 Thread Ulrich Eckhardt
Am 01.02.2012 10:32, schrieb Peter Otten: It doesn't matter for the OP (see Stefan Behnel's post), but If you want to replace characters in a unicode string the best way is probably the translate() method: print u\xa9\u2122 ©™ u\xa9\u2122.translate({0xa9: ucopy;, 0x2122: utrade;})

Re: Parsing a serial stream too slowly

2012-01-24 Thread Ulrich Eckhardt
Am 23.01.2012 22:48, schrieb M.Pekala: I think that regex is too slow for this operation, but I'm uncertain of another method in python that could be faster. A little help would be appreciated. Regardless of the outcome here, I would say that your code is still a bit wonky on the handling of

Re: verify the return value of a function

2012-01-20 Thread Ulrich Eckhardt
Am 19.01.2012 21:45, schrieb Jabba Laci: In a unit test, I want to verify that a function returns a cookielib.LWPCookieJar object. What is the correct way of doing that? 1) First I tried to figure out its type with type(return_value) but it istype 'instance' I'm not sure where the problem

Re: replacing __dict__ with an OrderedDict

2012-01-18 Thread Ulrich Eckhardt
Am 06.01.2012 12:44, schrieb Peter Otten: [running unit tests in the order of their definition] class Loader(unittest.TestLoader): def getTestCaseNames(self, testCaseClass): Return a sequence of method names found within testCaseClass sorted by co_firstlineno.

Re: replacing __dict__ with an OrderedDict

2012-01-10 Thread Ulrich Eckhardt
Am 10.01.2012 13:31, schrieb Lie Ryan: While it is possible to replace __dict__ with OrderedDict and it is possible to reorder the test, those are not his original problem, and the optimal solution to his original problem differs from the optimal solution to what he think he will need. Oh, and

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 13:10, schrieb Lie Ryan: I was just suggesting that what the OP thinks he wants is quite likely not what he actually wants. Rest assured that the OP has a rather good idea of what he wants and why, the latter being something you don't know, because he never bothered to explain

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 15:35, schrieb Roy Smith: The classic unittest philosophy says that tests should be independent of each other, which means they should be able to be run in arbitrary order. Some people advocate that the test framework should intentionally randomize the order, to flush out

replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hopefully make unittest execute my tests in the order of their declaration[2], so that

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Am 06.01.2012 12:44, schrieb Peter Otten: Alternatively you can write your own test loader: [...CODE...] Well, actually you just did that for me and it works! ;) Nonetheless, I'm still wondering if I could somehow replace the dict with an OrderedDict. Thank you! Uli --

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Ulrich Eckhardt
Am 06.01.2012 12:43, schrieb Lie Ryan: On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should

Re: argparse missing optparse capabilities?

2012-01-05 Thread Ulrich Eckhardt
Am 05.01.2012 09:05, schrieb ru...@yahoo.com: I have optparse code that parses a command line containing intermixed positional and optional arguments, where the optional arguments set the context for the following positional arguments. For example, myprogram.py arg1 -c33 arg2 arg3 -c44 arg4

check for a certain Python version

2011-12-20 Thread Ulrich Eckhardt
Hi! I'd like to give my users a meaningful error message when they are using obsolete Python versions. Is there some kind of best practice or recipe for that? Specifically, the case is a bunch of unittests that use features new to Python 2.7. Thank you! Uli --

nesting context managers

2011-12-20 Thread Ulrich Eckhardt
Hi! Let us assume I had a class HTTPClient that has a socket for HTTP and a logfile for filing logs. I want to make this HTTPClient a context manager, so that I can write with HTTPClient(url) as client: pass and reliably have both the socket and the logfile closed. The easy way is

Re: nesting context managers

2011-12-20 Thread Ulrich Eckhardt
Am 20.12.2011 15:15, schrieb Ulrich Eckhardt: Let us assume I had a class HTTPClient that has a socket for HTTP and a logfile for filing logs. I want to make this HTTPClient a context manager, so that I can write with HTTPClient(url) as client: pass Actually, I overestimated the task

Re: Making the case for typed lists/iterators in python

2011-12-19 Thread Ulrich Eckhardt
Am 16.12.2011 18:48, schrieb Nathan Rice: I realize this has been discussed in the past, I hope that I am presenting a slightly different take on the subject that will prove interesting. This is primarily motivated by my annoyance with using comprehensions in certain circumstances. [...]

modifying a time.struct_time

2011-12-16 Thread Ulrich Eckhardt
Hi! I'm trying to create a struct_time that is e.g. one year ahead or a month back in order to test some parsing/formatting code with different dates. Now, the straightforward approach is t = time.localtime() t.tm_year += 1 This fails with TypeError: readonly attribute. This kind-of

Re: modifying a time.struct_time

2011-12-16 Thread Ulrich Eckhardt
Am 16.12.2011 10:45, schrieb Ulrich Eckhardt: I'm trying to create a struct_time that is e.g. one year ahead or a month back in order to test some parsing/formatting code with different dates. There is something I stumbled across that helps and that is the datetime module, which seems more

Re: Screen Control Fullscreen ON/OFF

2011-12-15 Thread Ulrich Eckhardt
Am 15.12.2011 12:12, schrieb yeet: My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ OFF (white/black) thus seems to fit my 1-40Hz range. You might want to ask Santa for a new calculator, as in my book a response time of 2ms would be enough for 250Hz (period = 2 * 2ms).

Re: subprocess.Popen under windows 7

2011-12-09 Thread Ulrich Eckhardt
Am 08.12.2011 23:41, schrieb Frank van den Boom: arglist = [PATH_TO_7ZIP,a, -sfx, archive_name, *, -r, -p,PASSWORD] The * is resolved by the shell, this is not a wildcard that gets passed to the program. At least not normally, your case might be different. if output: print output

Re: Executing .pyc using python c api

2011-11-29 Thread Ulrich Eckhardt
Am 29.11.2011 08:34, schrieb Mrinalini Kulkarni: I need to run .pyc files using python c api. if i do PyImport_Import it executes the script. However, i need to pass a set of variables and their values which will be accessed from within the script. How can this be done. I don't think what you

Re: python shell that saves history of typed in commands that will persist between reboots

2011-11-25 Thread Ulrich Eckhardt
Am 25.11.2011 04:49, schrieb alex23: On Nov 24, 6:51 pm, Tim Goldenm...@timgolden.me.uk wrote: The Ctrl-Z thing is what *exits* the interpreter on Windows (a la Ctrl-D on Linux). With ActivePython, Ctrl-D works as well, which is a godsend as I'm constantly working across Windows linux. In

reading optional configuration from a file

2011-11-24 Thread Ulrich Eckhardt
Hi! I have a few tests that require a network connection. Typically, the target will be localhost on port 2. However, sometimes these settings differ, so I want to be able to optionally set them. What I'm currently doing is this: try: from settings import REMOTE_HOST,

Re: python shell that saves history of typed in commands that will persist between reboots

2011-11-24 Thread Ulrich Eckhardt
Am 17.11.2011 00:59, schrieb Ben Finney: David Robinowdrobi...@gmail.com writes: but your code works fine on Windows. Thanks. I'm glad to know that. Perhaps you could investigate why, and suggest an update to the above documentation if it's wrong? The bug tracker at

Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Ulrich Eckhardt
Am 18.11.2011 08:51, schrieb Pekka Kytölä: Is it possible to pass my own dll's (already loaded) handle as an argument to load/attach to the very same instance of dll? Thing is that I've done plugin (dll) to a host app and the SDK's function pointers are assigned once the dll is loaded in the

Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Ulrich Eckhardt
Am 18.11.2011 12:49, schrieb Pekka Kytölä: What I'd like to do is that after fetching those SDK function pointers I'd like to fire up .py/.pyc that snoops for possible plugins written in python and registers those plugins and callbacks and let them react to events. Obviously this python code

Re: unit-profiling, similar to unit-testing

2011-11-17 Thread Ulrich Eckhardt
Am 16.11.2011 15:36, schrieb Roy Smith: It's really, really, really hard to either control for, or accurately measure, things like CPU or network load. There's so much stuff you can't even begin to see. The state of your main memory cache. Disk fragmentation. What I/O is happening directly

unit-profiling, similar to unit-testing

2011-11-16 Thread Ulrich Eckhardt
Hi! I'm currently trying to establish a few tests here that evaluate certain performance characteristics of our systems. As part of this, I found that these tests are rather similar to unit-tests, only that they are much more fuzzy and obviously dependent on the systems involved, CPU load,

Re: Design Pattern and Python: Any book recommendation? Your view?

2011-11-04 Thread Ulrich Eckhardt
Am 04.11.2011 01:33, schrieb Anthony Kong: I would like to find out what is the current prevailing view or consensus (if any) on the use of Design Pattern in python? My consensus with myself is that design patterns are language-agnostic. If I write class Foo serves as view and controller for

Re: ctypes: catch system exit from C library

2011-11-03 Thread Ulrich Eckhardt
Am 03.11.2011 11:07, schrieb Martin Landa: in my python application I am calling functions from a C library via `ctypes` interface. Some fns from that C library calls `exit()` on error. Just curious, which library is that? Uli -- http://mail.python.org/mailman/listinfo/python-list

Re: Assign values from list to list of instances

2011-11-01 Thread Ulrich Eckhardt
Am 01.11.2011 16:05, schrieb Gnarlodious: I want to assign a list of variables: locus=[-2, 21, -10, 2, 12, -11, 0, 3] updating a list of objects each value to its respective instance: for order in range(len(Orders)): Orders[order].locus=locus[order] This works, even though it reads

Re: Exception Handling (C - extending python)

2011-10-25 Thread Ulrich Eckhardt
Am 23.10.2011 14:41, schrieb Stefan Behnel: That's just fine. If you are interested in the inner mechanics of the CPython runtime, reading the source is a very good way to start getting involved with the project. However, many extension module authors don't care about these inner mechanics and

<    1   2   3   4   5   >