Re: Python Error

2012-07-29 Thread Peter Otten
subhabangal...@gmail.com wrote: > Dear Group, > > I was trying to convert the list to a set, with the following code: > > set1=set(list1) > > the code was running fine, but all on a sudden started to give the > following error, > > set1=set(list1) > TypeError: unhashable type: 'list' > > plea

Re: newbie: write content in a file (server-side)

2012-07-29 Thread Peter Otten
Thomas Kaufmann wrote: > I send from a client file content to my server (as bytes). So far so good. > The server receives this content complete. Ok. Then I want to write this > content to a new file. It works too. But in the new file are only the > first part of the whole content. > > What's the

Re: Linux shell to python

2012-07-30 Thread Peter Otten
Vikas Kumar Choudhary wrote: > let me know if someone has tried to implement (grep and PIPE) shell > commands in python `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" > | cut -c1-7' > > I tried to use python subprocess and OS.Popen modules. subprocess is the way to go. > I was trying

Re: profiling and optimizing

2012-07-31 Thread Peter Otten
Rita wrote: > I recently inherented a large python process and everything is lovely. As > a learning experience I would like to optimize the code so I ran it thru > the profiler > > python -m cProfile myscript.py > > It seems majority of the time is taking in the deep copy but that seems to > co

Re: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-31 Thread Peter Billam
o available in call-compatible Lua version: http://www.pjb.com.au/comp/lua/MIDI.html and is closely related to the Perl CPAN module. You could consider posting Pyknon to comp.music.midi ; it's very low traffic, but some real gurus lurk there. All the best with your music, Peter -- Pet

Re: Error help

2012-08-02 Thread Peter Otten
danielashi...@googlemail.com wrote: > This error has been bugging me for days. I know it's minor, but it's > really getting in the way of my programming. I'm programming a data > analysis programme for a psychology experiment which takes pickled data > from the experiment and produces averages. Fo

Re: dbf.py API question

2012-08-03 Thread Peter Otten
Ethan Furman wrote: > SQLite has a neat feature where if you give it a the file-name of > ':memory:' the resulting table is in memory and not on disk. I thought > it was a cool feature, but expanded it slightly: any name surrounded by > colons results in an in-memory table. > > I'm looking at th

Re: find out whether a module exists (without importing it)

2012-08-07 Thread Peter Otten
Gelonida N wrote: > Is this possible. > > let's say I'd like to know whether I could import the module > 'mypackage.mymodule', meaning, > whther this module is located somewhere in sys.path > > i tried to use > > imp.find_module(), but > it didn't find any module name containing a '.' You coul

Re: Procedure to request adding a module to the standard library - or initiating a vote on it

2012-08-07 Thread Peter Otten
Helmut Jarausch wrote: > I'd like to request adding the module > > http://pypi.python.org/pypi/regex > > to Python's standard library in the (near) future or to even replace the > current 're' module by it. > > Personally I'm in need for fuzzy regular expressions and I don't see how > to do thi

Re: Procedure to request adding a module to the standard library - or initiating a vote on it

2012-08-07 Thread Peter Otten
Helmut Jarausch wrote: > On Tue, 07 Aug 2012 13:15:29 +0200, Peter Otten wrote: > >> I don't think that will help. From PEP 408: >> >> """ >> As part of the same announcement, Guido explicitly accepted Matthew >> Barnett's 'rege

Re: Unexpected behavior using contextmanager on a class method

2012-08-07 Thread Peter Otten
Thomas Draper wrote: > I want to use with..as in a "reversible circuit generator". However, it > seems that @contextmanager changes the expected nature of the class. I > tried to distill the problem down to a simple example. > > import contextlib > > class SymList: The problem you experience ha

Re: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs

2012-08-09 Thread Peter Otten
lipska the kat wrote: > If there isn't how does one go about > contributing to the documentation. http://docs.python.org/dev/py3k/bugs.html A similar link should be right there in the footer of the socketserver documentation. -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] A question about lists and strings

2012-08-10 Thread Peter Otten
Mok-Kong Shen wrote: > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both operators "+=" should

Re: pylagiarism -- Need help now! Please provide code...

2012-08-14 Thread Peter Otten
Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > > I need help putting together some code; today preferably, my boss is on > my back. Can someone please contribute a functioning module showing me >

Re: pylagiarism -- Need help now! Please provide code...

2012-08-14 Thread Peter Otten
Simon Cropper wrote: > Anyone willing to contribute money to help with the compilation of the > code will get a portion of the profits. Just send me your account > details, name and address; and I will ensure, once I have been paid, > that I will send you your cut! :) This is starting to look lik

Re: Strange behavior

2012-08-16 Thread Peter Otten
Virgil Stokes wrote: >>> def testFunc(startingList): >>>xOnlyList = []; j = -1 >>>for xl in startingList: >>>if (xl[0] == 'x'): >> That's going to fail in the starting list contains an empty string. Use >> xl.startswith('x') instead. > Yes, but this was by design (tacitly assumed that startingList

Re: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68'

2012-08-17 Thread Peter Otten
nepaul wrote: > ===case1==: > import sqlalchemy > test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a" > cmdTest1 = "select * from analyseresult where uid = " + test1 > engine = > sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpRe

Re: Regex Question

2012-08-18 Thread Peter Otten
Frank Koshti wrote: > I need to match, process and replace $foo(x=3), knowing that (x=3) is > optional, and the token might appear simply as $foo. > > To do this, I decided to use: > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > the issue with this is it doesn't match $foo by itself, and

New internal string format in 3.3, was Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 18 Aug 2012 19:34:50 +0100, MRAB wrote: > >> "a" will be stored as 1 byte/codepoint. >> >> Adding "é", it will still be stored as 1 byte/codepoint. > > Wrong. It will be 2 bytes, just like it already is in Python 3.2. > > I don't know where people are getting t

Re: New internal string format in 3.3

2012-08-19 Thread Peter Otten
Steven D'Aprano wrote: > On Sun, 19 Aug 2012 09:43:13 +0200, Peter Otten wrote: > >> Steven D'Aprano wrote: > >>> I don't know where people are getting this myth that PEP 393 uses >>> Latin-1 internally, it does not. Read the PEP, it explicitly

Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen?

2012-08-20 Thread Peter Otten
crispy wrote: > Thanks, i've finally came to solution. > > Here it is -> http://codepad.org/Q70eGkO8 > > def pairwiseScore(seqA, seqB): > > score = 0 > bars = [str(' ') for x in seqA] # ... > length = len(seqA) > similarity = [] > > for x in xrange(length): > > if

Re: python 6 compilation failure on RHEL

2012-08-20 Thread Peter Otten
John Nagle wrote: > On 8/20/2012 2:50 PM, Emile van Sebille wrote: >> On 8/20/2012 1:55 PM Walter Hurry said... >>> On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: >>> Package dependencies. If the OP intends to install a package that doesn't support other than 2.6, you inst

Abuse of subject, was Re: Abuse of Big Oh notation

2012-08-21 Thread Peter Otten
wxjmfa...@gmail.com wrote: > By chance and luckily, first attempt. > c:\python32\python -m timeit "('€'*100+'€'*100).replace('€' > , 'œ')" > 100 loops, best of 3: 1.48 usec per loop > c:\python33\python -m timeit "('€'*100+'€'*100).replace('€' > , 'œ')" > 10 loops, best of 3: 7.62 usec p

Re: unittest - sort cases to be run

2012-08-21 Thread Peter Otten
Kevin Zhang wrote: > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "Note that the order in which the various test cases will be run is > determined by sorting the test function names with respect to the built-in > ordering for strings." > >

Re: Objects in Python

2012-08-22 Thread Peter Otten
shaun wrote: > I'm having an issue its my first time using python and i set up a class > one of the methods is supposed to return a string but instead returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem to be > as well put together as Java. It's defini

Re: writelines puzzle

2012-08-22 Thread Peter Otten
William R. Wing (Bill Wing) wrote: > In the middle of a longer program that reads and plots data from a log > file, I have added the following five lines (rtt_data is fully qualified > file name): > > wd = open(rtt_data, 'w') > stat = wd.write(str(i)) > stat = wd.writelines(str(x_dates[:i])) > st

Re: Guarding arithmetic

2012-08-23 Thread Peter Otten
Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument > passed if there is no error, and 42 if there is one. So the setup is > something like: > > def safe(x): ># WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > >

Re: Guarding arithmetic

2012-08-23 Thread Peter Otten
Laszlo Nagy wrote: > def safe(deferred, default=42, exception=Exception): >> ... try: >> ... return deferred() >> ... except exception: >> ... return default > > What a beautiful solution! I was wondering if the following would be > possible: > > > def test(t

Re: Publish unittest results from test discovery

2012-08-25 Thread Peter Otten
Lucretiel wrote: > So I've started using unittest, and I love it. I use testdiscovery (python > -m unittest discover) so that I can distribute my tests and don't have to > manage them all manually. I wanted to start publishing my test results to > xml, though. I found xmlrunner by googling around,

Re: argparse localization support

2012-08-26 Thread Peter Otten
Kwpolska wrote: > I am using argparse in my project. I want to localize it, but it > seems to be impossible to change some things. See this, for example: > > usage: trash [-h] [-V] [-e] [-l] [-r] [-v] [-w] [PLIK [PLIK ...]] > > Trashman — menedżer śmietnika XDG w Pythonie. > > positional argu

Re: What do I do to read html files on my pc?

2012-08-28 Thread Peter Otten
mikcec82 wrote: > Il giorno lunedì 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: >> Hallo, >> >> >> >> I have an html file on my pc and I want to read it to extract some text. >> >> Can you help on which libs I have to use and how can I do it? >> >> >> >> thank you so much. >> >> >>

Re: Context manager to save/restore a name binding

2012-08-30 Thread Peter Otten
Ben Finney wrote: > I have written a context manager to save and restore a name binding:: > > import contextlib > > @contextlib.contextmanager > def preserve_value(namespace, name): > """ A context manager to preserve, then restore, the specified > binding. > >

Re: why i can't set locale?

2012-08-31 Thread Peter Otten
contro opinion wrote: locale.setlocale(locale.LC_ALL, 'gbk') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/locale.py", line 513, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting Try picking one of t

Re: how to get character hex number?

2012-08-31 Thread Peter Otten
Tim Chase wrote: > On 08/31/12 22:41, contro opinion wrote: >>> u"english".encode("utf-8") 'english' >>> u"english".encode("ascii") 'english' how can i get 656e676c697368 in encode method? >>> >>> At least in 2.x, you can do: >>> >>> >>> u"english".encode("hex") >>> '

Re: Tkinter bug in Entry widgets on OS X

2012-09-01 Thread Peter Otten
Arnaud Delobelle wrote: > On Friday, 31 August 2012, Dennis Lee Bieber wrote: > >> On Fri, 31 Aug 2012 15:41:01 GMT, Alister >> >> > >> declaimed the following in gmane.comp.python.general: >> >> > I agree that it is unexpected in a single line entry box but isn't the >> 1st >> > rule of user in

Re: Flexible string representation, unicode, typography, ...

2012-09-02 Thread Peter Otten
Ian Kelly wrote: > Rewriting the example to use locale.strcoll instead: sorted(li, key=functools.cmp_to_key(locale.strcoll)) There is also locale.strxfrm() which you can use directly: sorted(li, key=locale.strxfrm) -- http://mail.python.org/mailman/listinfo/python-list

Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

2012-09-02 Thread Peter Otten
Token Type wrote: > I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows: > > >>> text = nltk.corpus.brown.words(categories = 'news') > >>> def hedge(text): > for i in range(3,len(text),4): > new_text = text.insert(i, 'like') > return n

Re: Flexible string representation, unicode, typography, ...

2012-09-02 Thread Peter Otten
wxjmfa...@gmail.com wrote: > Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a écrit : >> Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > With a memory gain = 0 since my text contains non-latin-1 characters! I can't confirm this. At least users of wide builds will

Re: simple client data base

2012-09-03 Thread Peter Otten
Chris Angelico wrote: > You may also be needlessly reinventing the wheel. Aren't there already > several million basic contact databases around? Why roll your own? To learn a thing or two, and to stick it to the defeatists ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Chris Angelico wrote: > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: >> comparing every pair in a sample of 1000 8-char words >> taken from '/usr/share/dict/words' >> >> head >> 1: 477222

Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread Peter Otten
BobAalsma wrote: > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > I hav

Re: Python Interview Questions

2012-09-05 Thread Peter Otten
charvigro...@gmail.com wrote: > Finally I have decided to put best interview question and answers. > > Please visit http://***/web/CorePython/ for core python > and http://***/web/PythonAdvanced/ for advanced python Hm, are you a reformed PHP programmer who has never heard of sql injection atta

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Oscar Benjamin wrote: > On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote: >> def count_common(a, b): [sorry for seriously broken implementation] > This function will return 1 if the first character differs. It does not > count the number of common character

Re: how can i register the non-default browser with the webbrowser module?

2012-09-05 Thread Peter Otten
Levi Nie wrote: > how can i register the non-default browser with the webbrowser module? > > the case: > i want open a site such as "google.com" in ie8 with the python.But my > default is chrome. > so i want to register a ie8 controller with the > webbrowser.register(*name*, *constructor*[, *inst

Re: HTMLParser skipping HTML? [newbie]

2012-09-05 Thread Peter Otten
BobAalsma wrote: > [Didn't understand the bit about the kittens, though. How about that?] > > Oops, sorry, found that bit about logging in - asked too soon; still > wonder about the kittens ;) I just wanted to tell you not to mark the end of an if-suite with an "# end if" comment. As soon as yo

Re: Need help fixing this error please:NameError: global name is not defined

2012-09-06 Thread Peter Otten
shaun wrote: > I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: > def databasebatchcall(self,tid, bid): > con=cx_Oracle.connect( > 'user/user...@odb4.dcc.company/ODB4TEST.COMPANY.COM') > c

Re: confused in decorate and closure

2012-09-12 Thread Peter Otten
月忧茗 wrote: > HI, I have some test code: > > > def num(num): > def deco(func): > def wrap(*args, **kwargs): > inputed_num = num > return func(*args, **kwargs) > return wrap > return deco > > > @num(5) > def test(a): > return a + inputed_num >

Re: avoid the redefinition of a function

2012-09-13 Thread Peter Otten
MRAB wrote: > On 12/09/2012 19:04, Alister wrote: >> On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote: >> For example: def install_java(): pass def install_tomcat(): pass >>> >>> Thanks for the answers. I decided to use numbers in the name of the >>> fu

Re: cannot concatenate 'str' and 'list' objects

2012-09-15 Thread Peter Otten
Νικόλαος Κούρας wrote: > Τη Σάββατο, 15 Σεπτεμβρίου 2012 4:38:51 μ.μ. UTC+3, ο χρήστης Chris > Angelico έγραψε: >> On Sat, Sep 15, 2012 at 11:28 PM, Νικόλαος Κούρας >> wrote: >> >> > Iam not using frameworks just plain python code written in Notepad++ >> >> > >> >> > Can you please tell me how

Re: want to show list of available options and arguments in my command line utility

2012-09-16 Thread Peter Otten
Santosh Kumar wrote: > I have a script that takes an which basically takes a command line > argument and prints after processing. If I don't give the argument to > the script, it gives me a ValueError: > > ValueError: need more than 1 value to unpack > > I was trying to utilizing this space, if

BDFL Rossenbom, was Re: pythonOCC examples doesn't work?

2012-09-17 Thread Peter Otten
Dwight Hutto wrote: >>> Alan Gauld quotes, "Putting on my moderator's hat", sometimes. >>> is as you describe, a monarchy whose head but seldom exercises power; >>> >>> >>> I think it's Rossenbom(or whoever the creator of the interpreter >>> written in C is), "who says benevolent dictator for

Re: A little morning puzzle

2012-09-19 Thread Peter Otten
Neal Becker wrote: > I have a list of dictionaries. They all have the same keys. I want to > find the set of keys where all the dictionaries have the same values. Suggestions? >>> items = [ ... {1:2, 2:2}, ... {1:1, 2:2}, ... ] >>> first = items[0].items() >>> [key for key, value in first if

Re: A little morning puzzle

2012-09-19 Thread Peter Otten
Dwight Hutto wrote: >> I have a list of dictionaries. They all have the same keys. I want to >> find the >> set of keys where all the dictionaries have the same values. >> Suggestions? > > Here is my solution: > > > a = {} > a['dict'] = 1 > > b = {} > b['dict'] = 2 > > c = {} > c['dict'] =

Re: [Q] How to exec code object with local variables specified?

2012-09-20 Thread Peter Otten
Makoto Kuwata wrote: > Is it possible to run code object with local variables specified? > I'm trying the following code but not work: > > def fn(): >x = 1 >y = 2 > localvars = {'x': 0} > exec(fn.func_code, globals(), localvars) > print(localvars) > ## what I e

Re: [Q] How to exec code object with local variables specified?

2012-09-21 Thread Peter Otten
Makoto Kuwata wrote: > On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__pete...@web.de> wrote: >> >>>>> loc = {} >>>>> exec("x = 1; y = 2", globals(), loc) >>>>> loc >> {'y': 2, 'x': 1} >> >&

Re: how to do draw pattern with python?

2012-09-21 Thread Peter Otten
echo.hp...@gmail.com wrote: > may i know how to shift the bits using only looping and branching?? import time data = """\ xx .x..x. ..xx.. ..xx.. .x..x. xx """.splitlines() data = [line * 12 for line in data] # optional while True: print "\x1b[2J\x1b[0;0H" # optional for i, li

Re: How to apply the user's HTML environment in a Python programme?

2012-09-21 Thread Peter Otten
BobAalsma wrote: > Hmm, from the previous posts I get the impression that I could best solve > this by asking the user for the specific combination of username, password > and URL + promising not to keep any of that... > > OK, that does sound doable - thank you all Hmm, promising seems doable, b

Re: how to do draw pattern with python?

2012-09-21 Thread Peter Otten
Ismael Farfán wrote: > 2012/9/21 Peter Otten <__pete...@web.de>: >> echo.hp...@gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning t

Re: One of my joomla webpages has been hacked. Please help.

2012-09-22 Thread Peter Otten
Νίκος Γκρεεκ wrote: > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > Please visit my web page varsa.gr and view the source code and maybe you > can tell me what has happened. Do you use a password that was exposed in the other thread, http://mail.python.org/pipermail

Re: A dateutil error has appeared, due to updates? How to fix?

2012-09-23 Thread Peter Otten
tinn...@isbd.co.uk wrote: > I have a python script which uses the dateutil module with the > following:- > > import sys > import datetime > import icalendar > from dateutil.relativedelta import relativedelta > > The section of code which uses relativedelta is as follows:- > >

Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
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 override class attributes with the same name." As methods are usually defined in the class a

Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
alex23 wrote: > 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." >> >&g

Re: How to export a logging level?

2012-09-25 Thread Peter Otten
Vincent Vande Vyvre wrote: > In my application I import a module and I want to set the same logging > level as the main app to this module. Isn't that the default? If you set the logging level with basicConfig() that level should be applied to all messages. -- http://mail.python.org/mailman/

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-26 Thread Peter Otten
iMath wrote: > I only know the dollar sign ($) will match a pattern from the > end of a string,but which method does it work with ,re.match() or > re.search() ? Why not try it out in the interactive interpreter? Here's the "deluxe version": >>> def demo(pattern="mid$", texts=["start mid end",

Re: howto handle nested for

2012-09-28 Thread Peter Otten
Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): >

Re: howto handle nested for

2012-09-28 Thread Peter Pearson
On Fri, 28 Sep 2012 09:49:36 -0600, Ian Kelly wrote: > > levels = 6 > for combination in itertools.product(xrange(n_syms), levels): > # do stuff >>> n_syms = 3 >>> levels = 6 >>> for combination in itertools.product(xrange(n_syms), levels): ... print combination ... Traceback (most recent

Can't import modules

2012-09-30 Thread Peter Farrell
s not callable What am I doing wrong? Thanks! Peter Farrell San Mateo, CA -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't import modules

2012-09-30 Thread Peter Farrell
ath teacher/tutor who's trying to teach my students to understand math through using something real like Python. I'll keep you posted on my progress. Thank you in advance for your help! Peter On Sunday, September 30, 2012 1:22:31 PM UTC-7, Hans Mulder wrote: > On 30/09/12 21:42:37, Peter F

Re: Can't import modules

2012-09-30 Thread Peter Farrell
On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: > On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > > > > > Thanks for trying to help, everybody. Sorry I didn't post the whole > > > error message. Now my problem is I

Re: Can't import modules

2012-09-30 Thread Peter Farrell
On Sunday, September 30, 2012 8:19:28 PM UTC-7, Dave Angel wrote: > On 09/30/2012 09:35 PM, Peter Farrell wrote: > > > On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: > > >> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > >

Re: terminate called after throwing an instance of 'CABRTException'

2012-10-02 Thread Peter Otten
Daniel Fetchinson wrote: > I've noticed a strange thing with python lately: > > > > Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) > [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. def f(): print x > ... f() >

Re: unit testing class hierarchies

2012-10-02 Thread Peter Otten
Ulrich Eckhardt wrote: > As you see, the code for test_base() is redundant, so the idea is to > move it to a baseclass: > > class TestBase(unittest.TestCase): > def test_base(self): > ... > > class TestD1(TestBase): > def test_r(self): > ... > def test_s(self): >

Re: unit testing class hierarchies

2012-10-02 Thread Peter Otten
Ulrich Eckhardt wrote: > Am 02.10.2012 16:06, schrieb Thomas Bach: >> On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: >>> As you see, the code for test_base() is redundant, so the idea is to >>> move it to a baseclass: >>> >>> class TestBase(unittest.TestCase): >>> def test_b

Re: unit testing class hierarchies

2012-10-02 Thread Peter Otten
Fayaz Yusuf Khan wrote: > Peter Otten wrote: > >> Ulrich Eckhardt wrote: >>> The problem here is that TestBase is not a complete test case (just > as >>> class Base is not complete), but the unittest framework will still > try >>> to run it on its

Re: How can I hide my stack frames in a TestCase subclass?

2012-10-04 Thread Peter Otten
David Banks wrote: > I want to add a custom assert method to a TestCase subclass. I tried to > copy my implementation from the unittest module so that it would match > the behaviour of the regular TestCase as closely as possible. (I would > prefer to just delegate to self.assertEqual() but this

Re: How can I hide my stack frames in a TestCase subclass?

2012-10-05 Thread Peter Otten
Manuel Pégourié-Gonnard wrote: > Peter Otten scripsit : > >> David Banks wrote: >> >>> Note that the custom assert method causes a stack trace with two frames, >>> one inside the method itself, whereas the stock unittest method only has >>> one fram

Re: How can I hide my stack frames in a TestCase subclass?

2012-10-05 Thread Peter Otten
Manuel Pégourié-Gonnard wrote: > However, there was an implied question in the "documented" part: can > we rely on it? Isn't it considered an implementation detail (names > starting with underscores)? "Not documented" was my implied answer. I think you have a valid use case, though, so you could

Re: write binary with struct.pack_into

2012-10-06 Thread Peter Otten
palmeira wrote: > Dear pythonists, > > I'm having a problem with read/write binary in python. > I have a binary file that I need to read information, extract a array, > modify this array and put these values into file again in same binary > format. > I need to use unpack_from and pack_into becaus

Re: Convert MAC to hex howto

2012-10-07 Thread Peter Otten
Johannes Graumann wrote: > Dear all, > > I'm trying to convert > '00:08:9b:ce:f5:d4' > to > '\x00\x08\x9b\xce\xf5\xd4' > for use in magic packet construction for WakeOnLan like so: > wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >wolsocket.setsockopt(socket.SOL_SOCKET, sock

Re: Insert item before each element of a list

2012-10-08 Thread Peter Otten
mooremath...@gmail.com wrote: > What's the best way to accomplish this? Am I over-complicating it? My > gut feeling is there is a better way than the following: > import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x)))

Re: Insert item before each element of a list

2012-10-09 Thread Peter Otten
Duncan Booth wrote: > mooremath...@gmail.com wrote: > >> What's the best way to accomplish this? Am I over-complicating it? >> My gut feeling is there is a better way than the following: >> > import itertools > x = [1, 2, 3] > y = list(itertools.chain.from_iterable(('insertme', x[i]

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Michele Simionato wrote: > I have the following module implementing a registry of functions with a > decorator: > > $ cat x.py > registry = {} # global dictionary > > def dec(func): > registry[func.__name__] = func > print registry, id(registry) > return func > > if __name__ == '__m

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Grant Edwards wrote: > On 2012-10-09, Peter Otten <__pete...@web.de> wrote: > >> Welcome to python -- this is a trap every newbie falls into ;) >> >> Seriously, you shouldn't use the main script as a library; > > There must be something wrong with me.

Re: communicate with external process via pty

2012-10-10 Thread Peter Otten
Tim Arnold wrote: > I have an external process, 'tralics' that emits mathml when you feed it > latex equations. I want to get that mathml into a string. > > The problem for me is that tralics wants to talk to a tty and I've never > done that before; it basically starts its own subshell. > > I ha

Re: Delete duplicate rows in textfile - except it contains a "{" or "}"

2012-10-10 Thread Peter Otten
Joon Ki Choi wrote: > > Hello Pythonistas, > > i have a very large textfile with contents like: > > @INBOOK{Ackermann1999-b, > author = {Ackermann, K.-F. and Ackermann, K.-F. and Ackermann, K.-F. and > Ackermann, > K.-F. and Ackermann, K.-F. and Ackermann, K.-F. and Ackermann, K.-F. > and A

Re: __setitem__ without position

2012-10-12 Thread Peter Otten
Ethan Furman wrote: > Terry Reedy wrote: >> In 3.x, you would write __setitem__ to recognize that the 'key' is a >> slice object rather than an int and act accordingly. (In 2.x, you would >> write __setslice__.) > > I'm not sure how far back it goes, but at least from 2.4 forward > __setitem__ wo

[on topic] Re: readline trick needed

2012-10-16 Thread Peter Otten
Steven D'Aprano wrote: > I'm working with the readline module, and I'm trying to set a key > combination to process the current command line by calling a known > function, *and* enter the command line. > > Something along the lines of: > > * execute function spam() in some context where it can a

Re: [on topic] Re: readline trick needed

2012-10-16 Thread Peter Otten
Ned Deily wrote: > In article , Peter Otten <__pete...@web.de> > wrote: >> Steven D'Aprano wrote: >> > I'm working with the readline module, and I'm trying to set a key >> > combination to process the current command line by calling

[off topic], was Re: [on topic] Re: readline trick needed

2012-10-16 Thread Peter Otten
Dwight Hutto wrote: I knew I'd eventually regret putting "on topic" into the subject... Well done, Dwight. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python interactive help()

2012-10-19 Thread Peter Otten
Mark Lawrence wrote: > Where is this specific usage documented as my search engine skills have > let me down? find and grep ftw. > By this I mean entering help() without parameters to get > the following output and then the help> prompt. http://docs.python.org/dev/py3k/library/functions.html#

Re: How to see the __name__ attribute of a class by using dir()

2012-10-20 Thread Peter Otten
Jennie wrote: > The dir() built-in does not show the __name__ attribute of a class: > > >>> '__name__' in Foo.__dict__ > False > >>> Foo.__name__ > 'Foo' > > I implementd my custom __dir__, but the dir() built-in do not want to > call it: > > >>> class Foo: > ... @classmethod > ... d

Re: How to see the __name__ attribute of a class by using dir()

2012-10-20 Thread Peter Otten
Jennie wrote: > On 10/20/2012 10:24 AM, Peter Otten wrote: > >> So if you want to customise dir(Foo) you have to modify the metaclass: >> >>>>> >>>class Foo: >> ... class __metaclass__(type): >> ... def __dir__(self):

Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Chris Rebert wrote: > line.strip().split() No need to strip() if you are going to split on whitespace: >>> line = " a b c \n" >>> line.split() == line.strip().split() True Lest the new idiom takes on while you are bravely fighting the immortable readlines() ;) -- http://mail.python.org/mailm

Re: Split single file into multiple files based on patterns

2012-10-24 Thread Peter Otten
satyam wrote: > I have a text file like this > > A1980JE3937 2732 4195 12.527000 > A1980JE3937 3465 9720 22.00 > A1980JE3937 1853 3278 12.50 > A1980JE3937 2732 2732 187.50 > A1980JE3937 19 4688 3.619000 > A1980JE3937 2995 9720 6.667000 > A1980JE3937 1603 97

Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Peter Otten wrote: Brave new words: > immortable should be "immortal" -- http://mail.python.org/mailman/listinfo/python-list

[OT] Re: turn list of letters into an array of integers

2012-10-24 Thread Peter Otten
Dennis Lee Bieber wrote: > On Wed, 24 Oct 2012 11:04:38 +0200, Peter Otten <__pete...@web.de> > declaimed the following in gmane.comp.python.general: > >> Peter Otten wrote: >> >> Brave new words: >> >> > immortable >> >> should

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: > >> Wasn't there a Monty Python sketch where a man carrying a parrot in a >> cage comes into a shop full of stuffed animals and complains: No, I >> don't admire the taxiderm

Re: SSH Connection with Python

2012-10-25 Thread Peter Pearson
On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: > how can i create a SSH-Connection with python? I have to send some > commands to the remote host and parse their answers. > greatz Johannes I've been using Twisted (twistedmatrix.com). It is especially convenient for the server end. Its or

Re: SSH Connection with Python - Oops

2012-10-25 Thread Peter Pearson
On 25 Oct 2012 16:55:46 GMT, Peter Pearson wrote: > On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: >> how can i create a SSH-Connection with python? I have to send some >> commands to the remote host and parse their answers. >> greatz Johannes > &

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