Re: problems with tkinter updates

2012-01-24 Thread Peter Otten
y...@zioup.com wrote: > > I'm missing something about tkinter updates. How can I give tkinter a > chance to run? > > Here's some code: > > import time > import tkinter > import tkinter.scrolledtext > > tk = tkinter.Tk() > f = tkinter.Toplevel(tk) > st = tkinter.scrolledtext.ScrolledText(f) > s

Re: How to work around a unicode problem?

2012-01-24 Thread Peter Otten
tinn...@isbd.co.uk wrote: > I have a small python program that uses the pyexiv2 package to view > exif data in image files. > > I've hit a problem because I have a filename with accented characters > in its path and the pyexiv2 code traps as follows:- > > Traceback (most recent call last): >

Re: how to get my character?

2012-01-26 Thread Peter Otten
contro opinion wrote: > how can i get "你好" from '\xc4\xe3\xba\xc3' ? >>> print '\xc4\xe3\xba\xc3'.decode("gbk") 你好 General rule: use the decode() method to convert from bytestring to unicode and encode() to convert from unicode to bytestring. bytestring.encode(x) will implicitly try bytestrin

Re: problems with tkinter updates

2012-01-26 Thread Peter Otten
woooee wrote: [Peter Otten] >> line = next(infile, None) >> if line is not None: > if line is not None: probably does not work the way you expect. It does what I expect. > You might try > if line.strip(): > Take a look at this quick example > > t

Re: parse binary file

2012-01-29 Thread Peter Otten
contro opinion wrote: > please download the attachment ,and put in c:\test.data Your data didn't make it through. > and run the folloeing code: > > from struct import unpack > file_obj = open('c:\\test.data', 'r') Open the file in binary mode to disable CRNL-to-NL translation which will corr

RE: contextlib.contextmanager and try/finally

2012-01-31 Thread Peter Otten
Prasad, Ramit wrote: >>Like Neil mentioned, a contextmanager generator is wrapped with an >>__exit__ method that is guaranteed to be called and that explicitly >>resumes or closes the generator. So as long as your contextmanager >>generator is properly written (i.e. it yields exactly once), the >

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Peter Otten
Arnaud Delobelle wrote: >> Em 01-02-2012 01:39, Paulo da Silva escreveu: >>> What is the best way to iterate thru a huge list having the 1st element >>> a different process? I.e.: > Nobody mentioned itertools.islice, which can be handy, especially if > you weren't interested in the first element

Re: xhtml encoding question

2012-02-01 Thread Peter Otten
Ulrich Eckhardt wrote: > Am 31.01.2012 19:09, schrieb Tim Arnold: >> high_chars = { >> 0x2014:'—', # 'EM DASH', >> 0x2013:'–', # 'EN DASH', >> 0x0160:'Š',# 'LATIN CAPITAL LETTER S WITH CARON', >> 0x201d:'”', # 'RIGHT DOUBLE QUOTATION MARK', >> 0x201c:'“', # 'LEFT DOUBLE QUOTATI

Re: Generator problem: parent class not seen

2012-02-01 Thread Peter Otten
Russell E. Owen wrote: > I have an odd and very intermittent problem in Python script. > Occasionally it fails with this error: > > Traceback (most recent call last): > File > "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas > eFocusScript.py", line 884, in run > File >

Re: xhtml encoding question

2012-02-02 Thread Peter Otten
Ulrich Eckhardt wrote: > 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: >> >>>&

Re: how to read serial stream of data [newbie]

2012-02-07 Thread Peter Otten
Antti J Ylikoski wrote: > 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 backs

Re: Reading files in from the proper directory

2012-02-07 Thread Peter Otten
smac2...@comcast.net wrote: > Hello. I am admittedly a Python novice, and ran into some trouble > trying to write a program that will pull multiple excel files all into > one file, with each file on a different sheet. > > I am confident most of the code is correct, as the program runs > without a

Re: Reading files in from the proper directory

2012-02-07 Thread Peter Otten
smac2...@comcast.net wrote: > xls_files = glob.glob(in_dir + "*.xls") Try changing that to pattern = os.path.join(in_dir, "*.xls") xls_files = glob.glob(pattern) os.path.join() inserts a (back)slash between directory and filename if necessary. > merge_xls(in_dir="C:\Documents and Settings\

Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Chris Angelico wrote: > On Thu, Feb 9, 2012 at 2:55 PM, Steven D'Aprano > wrote: >> If your data is humongous but only available lazily, buy more memory :) > > Or if you have a huge iterable and only need a small index into it, > snag those first few entries into a list, then yield everything el

Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Mark Lawrence wrote: > I'm looking at a way of cycling around a sequence i.e. starting at some > given location in the middle of a sequence and running to the end before > coming back to the beginning and running to the start place. About the > best I could come up with is the following, any bett

Re: multiple namespaces within a single module?

2012-02-09 Thread Peter Otten
jkn wrote: > is it possible to have multiple namespaces within a single python > module? Unless you are abusing classes I don't think so. > I have a small app which is in three or four .py files. For various > reasons I would like to (perhaps optionally) combine these into one > file. Ren

Re: Formate a number with commas

2012-02-09 Thread Peter Otten
noydb wrote: > How do you format a number to print with commas? > > Some quick searching, i came up with: > import locale locale.setlocale(locale.LC_ALL, "") locale.format('%d', 2348721, True) > '2,348,721' > > > I'm a perpetual novice, so just looking for better, slicker, more

Re: Reading files in from the proper directory

2012-02-09 Thread Peter Otten
smac2...@comcast.net wrote: > On Feb 7, 3:16 pm, Peter Otten <__pete...@web.de> wrote: >> smac2...@comcast.net wrote: >> > xls_files = glob.glob(in_dir + "*.xls") >> >> Try changing that to >> >> pattern = os.path.join(in_dir, &qu

Re: Formate a number with commas

2012-02-09 Thread Peter Otten
Chris Rebert wrote: > On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <__pete...@web.de> wrote: >>>>> import locale >>>>> locale.setlocale(locale.LC_ALL, "") >> 'de_DE.UTF-8' >>>>> "{:n}".format(1234) # loca

Re: multiple namespaces within a single module?

2012-02-09 Thread Peter Otten
Ethan Furman wrote: > Peter Otten wrote: >> jkn wrote: >> >>> is it possible to have multiple namespaces within a single python >>> module? >> >> Unless you are abusing classes I don't think so. > > > Speaking of... > &

Re: multiple namespaces within a single module?

2012-02-10 Thread Peter Otten
jkn wrote: > Hi Peter > > On Feb 9, 7:33 pm, Peter Otten <__pete...@web.de> wrote: >> jkn wrote: >> > is it possible to have multiple namespaces within a single python >> > module? >> >> Unless you are abusing classes I don't think so.

Re: changing sys.path

2012-02-10 Thread Peter Otten
Andrea Crotti wrote: > Ok now it's getting really confusing, I tried a small example to see > what is the real behaviour, > so I created some package namespaces (where the __init__.py declare the > namespace package). > >/home/andrea/test_ns: >total used in directory 12 available 5655372

Re: changing sys.path

2012-02-10 Thread Peter Otten
Peter Otten wrote: > If it's a.c/a, that does not contain a c submodule or subpackage. Sorry, I meant a.b/a -- http://mail.python.org/mailman/listinfo/python-list

Re: changing sys.path

2012-02-10 Thread Peter Otten
Andrea Crotti wrote: > On 02/10/2012 03:27 PM, Peter Otten wrote: >> The package a will be either a.c/a/ or a.b/a/ depending on whether >> a.c/ or a.b/ appears first in sys.path. If it's a.c/a, that does not >> contain a c submodule or subpackage. > > >

Re: Python usage numbers

2012-02-12 Thread Peter Pearson
On 12 Feb 2012 09:12:57 GMT, Steven D'Aprano wrote: > > Suppose you're a fan of Russian punk bank Наӥв and you have a directory > of their music. Sigh. Banking ain't what it used to be. I'm sticking with classical Muzak. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://ma

Re: package extension problem

2012-02-13 Thread Peter Otten
Fabrizio Pollastri wrote: > Ok. To be more clear, consider the real python package Pandas. > > This package defines a Series class and a DataFrame class. > The DataFrame is a matrix that can have columns of > different type. > > If I write > > import pandas as pd > df = pd.DataFrame({'A':[1,2,3

Re: Reading sub-string from a file

2012-02-16 Thread Peter Otten
Smiley 4321 wrote: > I am a python newbie. Welcome! > Let's say I have a filename (test.conf) as below - > > > int Apple(int, int); > void Jump_OnUnload(float, int); > int Jockey_Apple_cat_1KK(float, int, char, int); > int Jockey_Apple_cat_look(int, float, int, int); > int Jockey_Apple_ca

Re: signed to unsigned

2012-02-17 Thread Peter Otten
Brad Tilley wrote: > In C or C++, I can do this for integer conversion: > > unsigned int j = -327681234; // Notice this is signed. > > j will equal 3967286062. I thought with Python that I could use struct > to pack the signed int as an unsigned int, but that fails: > x = struct.pack(" Tra

Re: PyKota, Python: AttributeError: 'module' object has no attribute '_quote'

2012-02-20 Thread Peter Otten
JohannesTU wrote: > Hello everyone, > > I'm new to linux/suse, but I was given the task to install the print > accounting software PyKota. > Before that I never even touched a linux system, so I don't have any basic > knowlegde at all! > Up to now I was able to solve all problems with the help of

Re: Inheriting from OrderedDict causes problem

2012-02-22 Thread Peter Otten
Bruce Eckel wrote: > Notice that both classes are identical, except that one inherits from > dict (and works) and the other inherits from OrderedDict and fails. > Has anyone seen this before? Thanks. > > import collections > > class Y(dict): > def __init__(self, stuff): > for k, v in

Re: unexpected behaviour playing with dynamic methods

2012-02-23 Thread Peter Otten
Marc Aymerich wrote: > Hi, > > I'm playing a bit with python dynamic methods and I came up with a > scenario that I don't understant. Considering the follow code: > > # Declare a dummy class > class A(object): > pass > > # generate a dynamic method and insert it to A class > for name in ['a

Re: What does exc_info do in a logging call?

2012-02-23 Thread Peter Otten
Roy Smith wrote: > In http://docs.python.org/release/2.6.7/library/logging.html, it says: > > logging.debug(msg[, *args[, **kwargs]]) > [...] > There are two keyword arguments in kwargs which are inspected: exc_info > which, if it does not evaluate as false, causes exception information to > be a

Re: sum() requires number, not simply __add__

2012-02-24 Thread Peter Otten
Buck Golemon wrote: > I feel like the design of sum() is inconsistent with other language > features of python. Often python doesn't require a specific type, only > that the type implement certain methods. > > Given a class that implements __add__ why should sum() not be able to > operate on that

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-24 Thread Peter Otten
Ethan Furman wrote: > Steven D'Aprano wrote: >> On Thu, 23 Feb 2012 16:30:09 -0800, Alex Willmer wrote: >> >>> This week I was slightly surprised by a behaviour that I've not >>> considered before. I've long used >>> >>> for i, x in enumerate(seq): >>># do stuff >>> >>> as a standard looping-

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-24 Thread Peter Otten
Rick Johnson wrote: > On Feb 23, 6:30 pm, Alex Willmer wrote: >> [...] >> as a standard looping-with-index construct. In Python for loops don't >> create a scope, so the loop variables are available afterward. I've >> sometimes used this to print or return a record count e.g. >> >> for i, x in en

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-24 Thread Peter Otten
Peter Otten wrote: > The code in the else suite executes only when the for loop is left via > break. Oops, the following statement is nonsense: > A non-empty iterable is required but not sufficient. Let me try again: A non-empty iterable is required but not sufficient to *skip*

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-24 Thread Peter Otten
Steven D'Aprano wrote: >> The code in the else suite executes only when the for loop is left via >> break. A non-empty iterable is required but not sufficient. > > You have a typo there. As your examples show, the code in the else suite > executes only when the for loop is NOT left via break (or

Re: Question about circular imports

2012-02-26 Thread Peter Otten
Frank Millman wrote: > I seem to have a recurring battle with circular imports, and I am trying > to nail it once and for all. > > Let me say at the outset that I don't think I can get rid of circular > imports altogether. It is not uncommon for me to find that a method in > Module A needs to acc

Re: pickle handling multiple objects ..

2012-02-26 Thread Peter Otten
Smiley 4321 wrote: > If I have a sample python code to be executed on Linux. How should I > handle multiple objects with 'pickle' as below - > > --- > #!/usr/bin/python > > import pickle > > #my_list = {'a': 'Apple', 'b': 'Mango', 'c': 'Orange', 'd': 'Pineapple'} > #my_list = ('Apple', 'Ma

Re: Error importing __init__ declared variable from another package

2012-02-28 Thread Peter Otten
Jason Veldicott wrote: > Hi, > > I have a simple configuration of modules as beneath, but an import error > is reported: > > /engine >(__init__ is empty here) >engine.py > /sim >__init__.py > > > The module engine.py imports a variable instantiated in sim.__init__ as > follows: >

Re: suppressing argparse arguments in the help

2012-02-28 Thread Peter Otten
Andrea Crotti wrote: > I have a script that might be used interactively but also has some > arguments that > should not be used by "normal" users. > So I just want to suppress them from the help. > I've read somewhere that the help=SUPPRESS should do what I want: > > parser.add_argument('-n'

Re: Pickle performing class instantiation ??

2012-02-28 Thread Peter Otten
Smiley 4321 wrote: > Am I doing the right thing for - > > - Have a class > - Instantiate the class with 3 parameters > - pickle the class instance > - generate a bytestream (.pkl) using pickle.dump, simply guessing - > > as - > > --- > #!/usr/bin/python > > import pickle > > class Pickle: >

Re: Need to write python source with python

2012-02-28 Thread Peter Otten
crs...@gmail.com wrote: > I'm new to Python but have experience with a few other programming > languages(Java, Perl, JavaScript). > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > a python class and functions from python. I will also need to later read > and edit the

Re: suppressing argparse arguments in the help

2012-02-28 Thread Peter Otten
Andrea Crotti wrote: > On 02/28/2012 04:02 PM, Peter Otten wrote: >> Andrea Crotti wrote: >> >>> I have a script that might be used interactively but also has some >>> arguments that >>> should not be used by "normal" users. >>>

Re: Need to write python source with python

2012-02-28 Thread Peter Otten
crs...@gmail.com wrote: > On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote: >> crs...@gmail.com wrote: >> >> > I'm new to Python but have experience with a few other programming >> > languages(Java, Perl, JavaScript). >> > >&

Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Peter Otten
Guillaume Chorn wrote: > Hello All, > > I have a .csv file that I created by copying and pasting a list of all the > players in the NBA with their respective teams and positions ( > http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO!). > Unfortunately, when I do this I have no

Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Peter Rubenstein
nd get:abcde Problem is I can't figure out what extract_from would look like, such that it would proceed dynamically down to the right level. I'm open to the possibility that I'm not approaching this the right way. If it helps, one member of my actual dict quoted below. So in real l

Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Peter Rubenstein
one member of my actual dict quoted below.  So in real life, something likedata_needed=['name','active-defects', 'admin-status:format', 'description', 'traffic-statistics:input-bps']etc. Thanks in advance,Peter { 'ge-0/0/0': {'active-al

RE: Help needed: dynamically pull data from different levels of a dict

2012-03-01 Thread Peter Rubenstein
data from different levels of a dict On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein wrote: > Hi, > > I'd appreciate a bit of help on this problem. I have some data that > I've converted to a dict and I want to pull out individual pieces of it. > > Simplified version-

Re: exec

2012-03-01 Thread Peter Otten
Rolf Wester wrote: > The reason to use exec is just laziness. I have quite a lot of classes > representing material data and every class has a number of parameters. > The parameter are Magnitude objects (they have a value and a unit and > overloaded special functions to correctly handle the units)

Re: exec

2012-03-01 Thread Peter Otten
Prasad, Ramit wrote: > Hi Peter, > > >>> class Magnitude(object): > > ... def __init__(self, value): > ... self.value = value > ... def __call__(self, uf=1): > ... if uf == 1: > ... return self

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? - If the added attributes' values are immutable, provide defaults as class attributes. - Implement an appropriate __setstate__() method. The easiest would be # unte

Re: Error with co_filename when loading modules from zip file

2012-03-06 Thread Peter Otten
Bob Rossi wrote: > On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: >> On Mar 6, 2:40 am, Bob Rossi wrote: >> >> > Darn it, this was reported in 2007 >> > http://bugs.python.org/issue1180193 >> > and it was mentioned the logging package was effected. >> > >> > Yikes. >> > >> >> I wi

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > Why don't you try it? > > py> import pickle > py> class C: > ... a = 23 > ... > py> c = C()

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Neal Becker wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >>> >>>> What happens if I pickle a class, and later unpickle it where the class >>>> now has adde

Re: pickle/unpickle class which has changed

2012-03-07 Thread Peter Otten
Gelonida N wrote: > Is there anyhing like a built in signature which would help to detect, > that one tries to unpickle an object whose byte code has changed? No. The only thing that is stored is the "protocol", the format used to store the data. > The idea is to distinguish old and new pickle

Re: Get tkinter text to the clipboard

2012-03-07 Thread Peter Otten
bugzilla-mail-...@yandex.ru wrote: > How can I get something from tkinter gui to another program ? > tkinter on python 3.2 on kde4 How about import tkinter root = tkinter.Tk() root.clipboard_clear() root.clipboard_append("whatever") -- http://mail.python.org/mailman/listinfo/python-list

sys.stdout.detach() results in ValueError

2012-03-07 Thread Peter Kleiweg
cript gives the following error: Exception ValueError: 'underlying buffer has been detached' in Same in Python 3.1.4 and Python 3.2.2 So, what do I do if I want to send binary data to stdout? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ -- http://mail.python.org/mailman/listinfo/python-list

what is best method to set sys.stdout to utf-8?

2012-03-07 Thread Peter Kleiweg
-up, type(sys.stdout) is , and it's also after using the second method. After using the first method, type(sys.stdout) is changed to . Should I always use the second method? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ -- http://mail.python.org/mailman/listinfo/python-list

Re: sys.stdout.detach() results in ValueError

2012-03-07 Thread Peter Kleiweg
Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > > I want to write out some binary data to stdout in Python3. I > > thought the way to do this was to call detach on sys.stdout. But > > apparently, you can

Re: newb __init__ inheritance

2012-03-08 Thread Peter Otten
Maarten wrote: > Alternatively you can figure out the parent class with a call to super: This is WRONG: > super(self.__class__, self).__init__() You have to name the current class explicitly. Consider: >> class A(object): ... def __init__(self): ... print "in a" ... >>

Re: Finding MIME type for a data stream

2012-03-09 Thread Peter Otten
Tobiah wrote: > I'm pulling image data from a database blob, and serving > it from a web2py app. I have to send the correct > Content-Type header, so I need to detect the image type. > > Everything that I've found on the web so far, needs a file > name on the disk, but I only have the data. > >

Re: How to know that two pyc files contain the same code

2012-03-10 Thread Peter Otten
Gelonida N wrote: > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. > > Unfortunately it seems, that .pyc files contain also something like the > time stamp of the related source file. > > So though two pyc files contain th

Re: newb __init__ inheritance

2012-03-11 Thread Peter Otten
Ian Kelly wrote: > On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >>> 2. Is the mro function available only on python3? >> >> No, but it is available only on new-style classes. If you try it on a >> classic class, you'll get an AttributeError. > > And by the way, you probably shouldn't call

Re: Global join function?

2012-03-14 Thread Peter Otten
Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv At this point there is probably an import that you have overlooked: from os.path import join > subprocess.call([join(home_dir, 'bin', 'easy_install'),

Re: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Peter Otten
Prasad, Ramit wrote: > So I have a context manager used to catch errors > > def __exit__( self, exceptionClass, exception, tracebackObject ): > if isinstance( exception, self.exceptionClasses ): > #do something here > > Normally exception would be the exception instance, but for > A

RE: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Peter Otten
Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> > if isinstance( exception, self.exceptionClasses ): >> > #do something here >> > >> > Normally excepti

Android

2012-03-16 Thread Peter Condon
Dear Sirs, I am a new student learning this and am getting an Android tablet for my birthday will python be able to run on android? Kindest regards Peter This email and any attachments to it may contain information which is confidential, legally privileged, subject to the Official

Re: How to get a reference of the 'owner' class to which a method belongs in Python 3.X?

2012-03-17 Thread Peter Otten
Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, the

Re: Using non-dict namespaces in functions

2012-03-18 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 17 Mar 2012 11:42:49 -0700, Eric Snow wrote: > >> On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano >> wrote: >>> Note that it is important for my purposes that MockChainMap does not >>> inherit from dict. >> >> Care to elaborate? > > I want to use collections.C

Re: filter max from iterable for grouped element

2012-03-19 Thread Peter Otten
Christian wrote: > as beginner in python , I struggle somewhat to filter out only the > maximum in the values for and get hmax. > h = {'abvjv': ('asyak', 0.9014230420411024), > 'afqes': ('jarbm', 0.9327883839839753), > 'aikdj': ('jarbm', 0.9503941616408824), > 'ajbhn': ('jarbm', 0.932358308

Re: Message passing between python objects

2012-03-19 Thread Peter Otten
J. Mwebaze wrote: > I am trying to learn about the interaction between python objects. One > thing i have often read is that objects interact by sending messages to > other objects to invoke corresponding methods. I am specifically > interested in tracing these messages and also probably log the m

Re: Distribution

2012-03-20 Thread Peter Otten
prince.pangeni wrote: > Hi all, >I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix

Re: code for computing and printing list of combinations

2012-03-20 Thread Peter Otten
Joi Mond wrote: > Can someone help me with the proper code to compute combinations for n=7, > r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There > should be 21 combination. Also once there list is made can a code be > written to add (sum) each of the set of five number in the t

Re: class checking its own module for an attribute

2012-03-21 Thread Peter Otten
Rod Person wrote: > We have a module called constants.py, which contains [whatever] related to > server names, databases, service account users and their passwords. Passwords? > In order to be able to use constants as command line parameters for > calling from our batch files I created the class

Re: Accessing the files by last modified time

2012-03-22 Thread Peter Otten
Sangeet wrote: > I've been trying to write a script that would access the last modified > file in one of my directories. I'm using Win XP. import os import glob path = r"c:\one\of\my directories\*" youngest_file = max(glob.glob(path), key=os.path.getmtime) -- http://mail.python.org/mailman/li

Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-03-23 Thread Peter Otten
Ethan Furman wrote: > Nathan Rice wrote: >> Logo. It's turtles all the way down. > > +1 QOTW Surely you're joking, Mr Furman! -- http://mail.python.org/mailman/listinfo/python-list

Re: random number

2012-03-26 Thread Peter Otten
Nikhil Verma wrote: > I want something to achieve like this :- > > def random_number(id): # I am passing it from request > # do something > return random_number > > Output > > random_number(5) > AXR670 That's normally not called a number (though it could be base 36 or similar). > One

Re: Is there any difference between print 3 and print '3' in Python ?

2012-03-26 Thread Peter Otten
redstone-c...@163.com wrote: > I know the print statement produces the same result when both of these two > instructions are executed ,I just want to know Is there any difference > between print 3 and print '3' in Python ? The question you really wanted to ask is: under what circumstances will th

"convert" string to bytes without changing data (encoding)

2012-03-28 Thread Peter Daum
Hi, is there any way to convert a string to bytes without interpreting the data in any way? Something like: s='abcde' b=bytes(s, "unchanged") Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Peter Daum
On 2012-03-28 11:02, Chris Angelico wrote: > On Wed, Mar 28, 2012 at 7:56 PM, Peter Daum wrote: >> is there any way to convert a string to bytes without >> interpreting the data in any way? Something like: >> >> s='abcde' >> b=bytes(s, "unchang

Re: question about file handling with "with"

2012-03-28 Thread Peter Otten
Jabba Laci wrote: > Is the following function correct? Yes, though I'd use json.load(f) instead of json.loads(). > Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) The file will be closed when the wit

Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Peter Daum
On 2012-03-28 12:42, Heiko Wundram wrote: > 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

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

2012-03-29 Thread Peter Otten
Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception *type* >> acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various

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

2012-03-29 Thread Peter Otten
Ulrich Eckhardt wrote: > True. Normally. I'd adapting to a legacy system though, similar to > OSError, and that system simply emits error codes which the easiest way > to handle is by wrapping them. If you have err = some_func() if err: raise MyException(err) the effort to convert it to e

Re: "convert" string to bytes without changing data (encoding)

2012-03-29 Thread Peter Daum
ogateescape" without the "_" and in python 3.1 it exists, but only not as a keyword argument: "s=b.decode('utf-8','surrogateescape')" ...) Thank you very much for your constructive advice! Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to structure data for efficient searching

2012-04-02 Thread Peter Otten
larry.mart...@gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4 fields: K3, K4, K5, and a > timestamp.

Re: why can't I pickle a class containing this dispatch dictionary?

2012-04-03 Thread Peter Otten
jkn wrote: > I'm clearly not understanding the 'can't pickle instancemethod > objects' error; can someone help me to understand, I think classes implemented in C need some extra work to make them picklable, and that hasn't been done for instance methods. > & maybe suggest a > workaround, (

Re: Is Programing Art or Science?

2012-04-03 Thread Peter Davis
On 3/30/2012 4:27 AM, Xah Lee wrote: Is Programing Art or Science? Programming itself is a bit like being a natural language translator for an autistic person. You have to understand the "message" to be communicated, and then interpret it *very* literally for the listener. Note that progra

Re: why can't I pickle a class containing this dispatch dictionary?

2012-04-03 Thread Peter Otten
jkn wrote: > Hi Peter > > On Apr 3, 8:54 am, Peter Otten <__pete...@web.de> wrote: >> jkn wrote: >> > I'm clearly not understanding the 'can't pickle instancemethod >> > objects' error; can someone help me to understand, >> >

Re: Is there a better way to do this snippet?

2012-04-03 Thread Peter Otten
python wrote: > I played around with a few things and this works but was wondering if > there was a better way to do this. > My first thought was list comprehension but could not get a figure out > the syntax. > > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary whe

Re: pygame.Rect question

2012-04-09 Thread Peter Pearson
On Sun, 8 Apr 2012 16:58:01 -0700 (PDT), Scott Siegler wrote: [snip] > I set rect.left to 30, rect.top to 30 and rect.width = 20 > > This works fine. However, when looking at rect.right() it > shows that it is equal to 50. I suppose this is equal to > 30+20. However, since the first pixel is on l

Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Peter Otten
tkp...@gmail.com wrote: > I using Python 3.2 and have a dictionary d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} > > whose values are lists I would like to zip into a list of tuples. If I > explicitly write: list(zip([1,2], [1,2,3], [1,2,3,4]) > [(1, 1, 1), (2, 2, 2)] > > I get exactly what I

Re: Zipping a dictionary whose values are lists

2012-04-13 Thread Peter Otten
Alexander Blinne wrote: > zip(*[x[1] for x in sorted(d.items(), key=lambda y: y[0])]) Why not zip(*[x[1] for x in sorted(d.items())])? -- http://mail.python.org/mailman/listinfo/python-list

Re: sort by column a csv file case insensitive

2012-04-15 Thread Peter Otten
Lee Chaplin wrote: > Hi all, > > I am trying to sort, in place, by column, a csv file AND sort it case > insensitive. > I was trying something like this, with no success: > > import csv > import operator > > def sortcsvbyfield(csvfilename, columnnumber): > with open(csvfilename, 'rb') as f: >

Re: escaping

2012-04-16 Thread Peter Otten
Kiuhnm wrote: > On 4/16/2012 4:42, Steven D'Aprano wrote: >> On Sun, 15 Apr 2012 23:07:36 +0200, Kiuhnm wrote: >> >>> This is the behavior I need: >>> path = path.replace('\\', '') >>> msg = ". {} .. '{}' .. {} .".format(a, path, b) >>> Is there a better way? >> >> >> This works fo

Re: how do i merge two sequence

2012-04-18 Thread Peter Otten
Python Email wrote: > how do i merge two seqs alernative; > > ("xyz", "7890") > output: x7y8z90 >>> import itertools >>> "".join(a+b for a, b in itertools.izip_longest("xyz", "7890", fillvalue="")) 'x7y8z90' -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions, help?

2012-04-18 Thread Peter Otten
Sania wrote: > Hi, > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. N

Re: Regular expressions, help?

2012-04-18 Thread Peter Otten
Sania wrote: > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. No. A r

Re: how do i merge two sequence

2012-04-18 Thread Peter Otten
Ervin Hegedüs wrote: > On Wed, Apr 18, 2012 at 10:41:00PM +0200, Peter Otten wrote: >> Python Email wrote: >> >> > how do i merge two seqs alernative; >> > >> > ("xyz", "7890") >> > output: x7y8z90 >> >> >

<    1   2   3   4   5   6   7   8   9   10   >