Re: Screen scraper to get all 'a title' elements

2015-11-25 Thread TP
On Wed, Nov 25, 2015 at 12:42 PM, ryguy7272 wrote: > Hello experts. I'm looking at this url: > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names Wildly offtopic but interesting, easy way to grab/analyze Wikipedia data using F# instead of Python http://evelinag.com/blog/2015/11-18-f-tac

Re: Trees

2015-01-20 Thread TP
On Mon, Jan 19, 2015 at 6:46 PM, Mark Lawrence wrote: > I don't know if you've seen this http://kmike.ru/python-data-structures/ > but maybe of interest. > I haven't read but also possibly of interest: Data Structures and Algorithms in Python by Michael T. Goodrich, Roberto Tamassia, Michael H.

Re: I love assert

2014-11-27 Thread TP
On Tue, Nov 11, 2014 at 11:40 AM, Peter Cacioppi wrote: > I get the impression that most Pythonistas aren't as habituated with > assert statements as I am. Is that just a misimpression on my part? If not, > is there a good reason to assert less with Python than other languages? > > As far as I ca

Re: Python IDE.

2014-11-20 Thread TP
On Thu, Nov 20, 2014 at 11:29 AM, Irmen de Jong wrote: > PyCharm *is* free, if you fall in one of several categories. > See http://www.jetbrains.com/pycharm/buy/license-matrix.jsp > > Even when you have to buy it, it is cheap (IMO) for what it offers. > "PyCharm Editions Comparison" [1] is a bet

Re: I love assert

2014-11-11 Thread TP
On Tue, Nov 11, 2014 at 11:40 AM, Peter Cacioppi wrote: > I think one needs to take care with some basic assert coding - it's not a > substitute for unit tests, it doesn't absolve you of normal exception > responsibilities, and, most of all, it should be used for passive > inspection and not acti

Re: Regex substitution trouble

2014-10-28 Thread TP
On Tue, Oct 28, 2014 at 4:02 AM, wrote: > Hi everyone, > > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substitute > all the occurences i

Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-05 Thread TP
On Tue, Aug 5, 2014 at 12:25 PM, Duncan Booth wrote: > So far they seem to have kept a pretty low profile; I suspect largely > because until recently PTVS only worked with the pay versions of Visual > Studio. > Not true. When it didn't work with the free express versions of VS, it worked with th

Re: Windows Studio 2008 Download

2014-07-29 Thread TP
On Tue, Jul 29, 2014 at 5:54 AM, Colin J. Williams wrote: > ii. The Service Pack 1 has the original studio as a prerequisite. That is > no longer available from Microsoft. I haven't tried it but the Visual Studio 2008 Professional 90 Day Trial iso *is* available from Microsoft at [1]. This doe

Re: Windows Studio 2008 Download

2014-07-28 Thread TP
Hmmm. Now that I think about it the full Microsoft Visual Studio 2008 Service Pack 1 download I mentioned in my last email probably needs to have Visual Studio 2008 already installed (it's been a number of years since I had to install VS2008)? You could try it and see if it works. If not download

Re: .Net Like Gui Builder for Python?

2014-07-25 Thread TP
On Fri, Jul 25, 2014 at 7:40 PM, Chris Angelico wrote: > The OP asked for two things, which I'll separate because they're > actually quite different. > > 1) Drag and drop widgets to create a window > 2) Double-click a widget to edit its code (presumably event handler) > > I have used a number of

Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-19 Thread TP
On Sat, Jul 19, 2014 at 12:28 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > For Python users, the IDEs from > Wingware and Activestate are notable: > > https://wingware.com/ > http://komodoide.com/ > I would say that since PyCharm (https://www.jetbrains.com/pycharm/

Re: Editor for Python

2014-01-09 Thread TP
On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ wrote: > > Hello, > > I'm looking for an editor for Python.I' m interested it works on > Windows.Can > > anybody help me? > It's an IDE rather than "just" an editor but how about PyCharm 3 Community Edition? [1] [1] https://ww

Re: Download Visual Studio Express 2008 now

2013-08-29 Thread TP
On Thu, Aug 29, 2013 at 2:43 AM, Philip Inglesant wrote: > Hi Martyn, > > Thanks for the good advice to download VS 2008 before M$ delete it from > their download servers. > > Unfortunately they have already done this so many Python modules now can't > be compiled correctly on Windows! > > Best r

Re: My son wants me to teach him Python

2013-06-13 Thread TP
On Wed, Jun 12, 2013 at 1:02 PM, Chris Angelico wrote: > I put the question to the > list, and got back a number of excellent and most useful answers > regarding book recommendations, and we ended up going with (if memory > serves me) Think Python [1] > Here's a link [1] to Chris' original quest

Re: Python teaching book recommendations: 3.3+ and with exercises

2013-05-03 Thread TP
[Just a note, all the book links in my original post have complete table of contents listing, so don't just take my word on their suitability.] Here's some I missed: Programming in Python 3, 2nd Edition - Mark Summerfield (Addison-Wesley, 2009) [1a]. Exercises. Solutions available online. At a qu

Re: Python teaching book recommendations: 3.3+ and with exercises

2013-05-02 Thread TP
On Thu, May 2, 2013 at 7:36 AM, Chris Angelico wrote: > One of my younger brothers, still school age, is to be studying some > aspect of computing for the next term or two. I strongly recommended > he learn Python (it has a bit more future than studying the internals > of OS/2), and my/his father

using "*" to make a list of lists with repeated (and independent) elements

2012-09-26 Thread TP
copies a list, he copies in fact the *pointer* to the list, such that we obtain this apparently strange behavior. Is it the correct explanation? In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" without this behavior? Thanks, TP -- http://mail.python.org/mailman/listinfo/python-list

Re: Is the Usenet to mailing list gateway borked?

2011-07-01 Thread TP
e Kopien per E-Mail. / Please do not Cc: me. > -- > http://mail.python.org/mailman/listinfo/python-list > Not sure if this is relevant. I use mail.google.com to follow mailing lists and a large proportion of python-list traffic ends up in my gmail spam folder for some reason? -- TP -- http://mail.python.org/mailman/listinfo/python-list

Re: Python IDE/text-editor

2011-04-16 Thread TP
On Sat, Apr 16, 2011 at 2:32 AM, jacek2v wrote: > On Apr 16, 11:18 am, Daniel Kluev wrote: >> > Please continue your recommendations. >> >> WingIDE has all that and much more, if you are willing to consider >> non-free IDE. >> Its multi-threading debugger definitely worth the cost of Pro version

Re: Use the Source Luke

2011-01-29 Thread TP
project: http://tpgit.github.com/MDIImageViewer/imageviewer.html. You can even view the Sphinx documentation "code" by clicking the "Show Source" link on the left. -- TP -- http://mail.python.org/mailman/listinfo/python-list

Re: list parameter of a recursive function

2010-10-07 Thread TP
Seebs wrote: > On 2010-10-07, TP wrote: >> Diez B. Roggisch wrote: >>> A safer alternative for these cases is using tuples, because they are >>> immutable. > >> The problem with tuples is that it is not easy to modify them: > > This is probably the be

Re: list parameter of a recursive function

2010-10-06 Thread TP
Steven D'Aprano wrote: >> I think I prefer doing an explicit copy.copy, because it allows to >> remind the reader that it is very important to take care of that. > > I think a comment is better for that. It's better to explicitly say > something is important than to assume the reader will guess.

Re: list parameter of a recursive function

2010-10-06 Thread TP
Diez B. Roggisch wrote: > Back to your example: your solution is perfectly fine, although a bit > costly and more error-prone if you happen to forget to create a copy. > A safer alternative for these cases is using tuples, because they are > immutable. Thanks Diez for your explanation. The proble

Re: list parameter of a recursive function

2010-10-06 Thread TP
Chris Torek wrote: >>import copy from copy > > [from copy import copy, rather] Yes, sorry. > Note that if f() is *supposed* to be able to modify its second > parameter under some conditions, you would want to make the copy > not at the top of f() but rather further in, and in this case, > that

list parameter of a recursive function

2010-10-06 Thread TP
Hi, I have a function f that calls itself recursively. It has a list as second argument, with default argument equal to None (and not [], as indicated at: http://www.ferg.org/projects/python_gotchas.html#contents_item_6 ) This is the outline of my function: def f ( argument, some_list = None ):

adding a method to an existing builtin class

2010-09-26 Thread TP
Hi everybody, Today I have learned a bit of the news of Python 3.0 compared to 2.4 version. By the way, I have asked myself if it is possible to add a method to a builtin type as 'unicode': >>> a="foo" >>> type(a) >>> print(dir(a)) ['__add__', ..., 'zfill'] For example, I would like to add a

Re: equivalent of bash "set -x" in Python

2010-09-26 Thread TP
James Mills wrote: > What do you mean by "command" ? For example, print statements, but it could extend to class definitions, etc. I am going to examine the solution given by Chris. Cheers, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When

equivalent of bash "set -x" in Python

2010-09-26 Thread TP
Hi everybody, I am interested in having the possibility to print every Python commands in a script (for didactic purpose). So I am looking for some sort of equivalent of bash "set -x". Does it exist? Thanks Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(5

Re: highlight words by regex in pdf files using python

2010-03-18 Thread TP
On Wed, Mar 17, 2010 at 7:53 AM, Peng Yu wrote: > On Tue, Mar 16, 2010 at 11:12 PM, Patrick Maupin wrote: >> On Mar 4, 6:57 pm, Peng Yu wrote: >>> I don't find a general pdf library in python that can do any >>> operations on pdfs. >>> >>> I want to automatically highlight certain words (using r

Am I using ctypes correctly? Where are fprints going?

2010-02-15 Thread TP
>From the Cplusplus-sig, I gathered that instead of Boost.Python I should use ctypes for the following problem. But let me make sure I'm using it correctly. I am calling the C Leptonica Image Processing C Library (http://leptonica.com) from python. Within its leptprotos.h file are functions like

Re: intricated functions: how to share a variable

2009-08-05 Thread TP
Bearophile wrote: > So probably a better solution is to just use the normal function > semantics: you pass them an argument and you take an argument as > return value. Such return value will be the new version of the value > you talk about. Thanks for your answer. Yes, it is better like this. My

intricated functions: how to share a variable

2009-08-05 Thread TP
Hi everybody, See the following example: # def tutu(): def toto(): print a a = 4 print a a=2 toto() tutu() ## I obtain the following error: "UnboundLocalError: local variable 'a' referenced before assignment" This is because Python looks i

Re: how to get back an object from its id() value

2009-04-08 Thread TP
MRAB wrote: > You could create a dict with the string as the key and the object as the > value. Thanks. But it implies an additional data structure: a dictionnary. I don't know what is the best: * using an additional dict and maintaining it * or using the "di" module proposed by CTO If "di" is r

how to get back an object from its id() value

2009-04-08 Thread TP
Hi everybody, I have a data structure (a tree) that has one constraint: I can only store strings in this data structure. To know if an object foo already exists in memory, I store "str(id(foo))" in the data structure. OK. But how do I get a usable reference from the id value? For example, if "fo

double/float precision question

2009-04-01 Thread TP
Hi everybody, Try the following python statements: >>> "%.40f" % 0.222 '0.098864108374982606619596' >>> float( 0.222) 0.1 It seems the first result is the same than the following C program: #

Re: modifying a list element from a function

2009-03-30 Thread TP
Adrian Dziubek wrote: > Could you explain your high level goal for this? It looks like a very > wicked way of doing things. Have You tried to read the list methods' > documentation? Maybe there you find something you need (like > list.index)? Hello, I have a "disambiguation" function that modifi

modifying a list element from a function

2009-03-27 Thread TP
Hi everybody, Be a the following list, containing list elements which second field is a string. >>> a = [ [4, "toto"], [5, "cou"] ] >>> a[0][1]="tou" >>> a [[4, 'tou'], [5, 'cou']] OK. Now, I want: * to do the same modification on the list "a" within a function * not to hardcode in this functio

context not cleaned at the end of a loop containing yield?

2009-03-26 Thread TP
Hi everybody, This example gives strange results: def foo( l = [] ): l2 = l print l2 for i in range(10): if i%2 == 0: l2.append( i ) yield i >>> [i for i in ut.foo()] [] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> [i for i in ut.foo()] [0, 2, 4,

Re: how to prevent python import from looking into the current directory

2009-03-06 Thread TP
Benjamin Peterson wrote: > While the solutions given by others in this thread will work, I think it > is best policy to not name your own modules after stdlib ones. When I see > "os" referenced in code, I assume it is the stdlib one, and don't want to > be confused by the presence of your own modu

Re: how to prevent python import from looking into the current directory

2009-03-06 Thread TP
Ben Finney wrote: > (Could you please set a valid email address for people to contact you > if necessary?) Thanks a lot for your help. My email address is in my signature: -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly

how to prevent python import from looking into the current directory

2009-03-06 Thread TP
Hi everybody, I would like to prevent the loading of modules in the current directory. For example, if I have a personal module in the current directory named "os", when I do "import os", I would like Python to import os standard module, not my personal module of the current directory. Is this pos

distutils: "build" command

2009-03-05 Thread TP
Hi everybody, I have programmed a python package, and I would like to use distutils with it. My package has the following structure after doing sdist and build: $ python setup.py sdist [...] $ python setup.py build [...] $ tree . |-- MANIFEST |-- MANIFEST.in |-- README |-- build | `-- lib |

setattr question

2009-02-19 Thread TP
Hi everybody, I try to make a "link" (or shortcut, if you want) so that len(b_instance) computes in fact len(a) (see the code below). I could write a method __len__ to b, but I wonder if it is possible to make it with a setattr/getattr trick, as I do below. Thanks in advance, Julien ###

super behavior

2009-01-25 Thread TP
Hi, Hereafter is an example using super. At the execution, we obtain: coucou init_coucou2 coucou1 coucou2 Traceback (most recent call last): File "essai_heritage.py", line 34, in print b.a AttributeError: 'coucou' object has no attribute 'a' Why Python does not enter in the __init__ metho

Re: is this pythonic?

2009-01-22 Thread TP
Peter Otten wrote: > If you can change the rest of your program to work smoothly with a > dictionary I would suggest the following: [snip] >>> from collections import defaultdict [snip] Thanks a lot. I didn't know defaultdict. It is powerful. I begin to understand that people prefer using dictio

Re: is this pythonic?

2009-01-21 Thread TP
alex23 wrote: > Try not to use 'dict' or the name of any of the other built-in types > as labels. Ops... Moreover I know it... > You're stepping through an entire list just to pass another list to > l.remove to step through and remove items from...in fact, given that > list.remove deletes th

is this pythonic?

2009-01-21 Thread TP
Hi, Is the following code pythonic: >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}] >>> dict = [ dict for dict in l if dict['title']=='ti'] >>> l.remove(*dict) >>> l [{'title': 'to', 'value': 2}] Precision: I have stored data in the list of dictionaries l, because in my applica

exec in a nested function yields an error

2009-01-13 Thread TP
Hi everybody, Try the following program: def f(): def f_nested(): exec "a=2" print a f() It yields an error. $ python nested_exec.py File "nested_exec.py", line 3 exec "a=2" SyntaxError: unqualified exec is not allowed in functi

trying to modify locals() dictionary

2009-01-12 Thread TP
Hi everybody, I try to modify locals() as an exercise. According to the context (function or __main__), it works differently (see below). Why? Thanks Julien def try_to_modify_locals( locals_ ): locals_[ "a" ] = 2 print "locals_[ 'a' ]=", locals_[

change only the nth occurrence of a pattern in a string

2008-12-31 Thread TP
Hi everybody, I would like to change only the nth occurence of a pattern in a string. The problem with "replace" method of strings, and "re.sub" is that we can only define the number of occurrences to change from the first one. >>> v="coucou" >>> v.replace("o","i",2) 'ciuciu' >>> import re >>> re

best way to do this

2008-12-02 Thread TP
Hi everybody, >>> c=[(5,3), (6,8)] >From c, I want to obtain a list with 5,3,6, and 8, in any order. I do this: >>> [i for (i,j) in c] + [ j for (i,j) in c] [5, 6, 3, 8] Is there a quicker way to do this? Thanks Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\

Re: how to construct a list of only one tuple

2008-11-27 Thread TP
[EMAIL PROTECTED] wrote: >> >>> a=("1","2") >> >>> b=[("3","4"),("5","6")] >> >>> list(a)+b >> ['1', '2', ('3', '4'), ('5', '6')] > a = ("1", "2") b = [("3", "4"), ("5", "6")] [a] + b > [('1', '2'), ('3', '4'), ('5', '6')] Thanks a lot. Why this difference of behavior between list

how to construct a list of only one tuple

2008-11-27 Thread TP
Hi, If I do: >>> a=("1","2") >>> b=[("3","4"),("5","6")] >>> list(a)+b ['1', '2', ('3', '4'), ('5', '6')] I would like rather to obtain: [('1', '2'), ('3', '4'), ('5', '6')] Am I compelled to do: >>> c=[] >>> c.append(a) >>> c+b [('1', '2'), ('3', '4'), ('5', '6')] Thanks Julien -- python

how to document a property

2008-11-27 Thread TP
Hi everybody, I know how to document a function or a method, with a docstring (see below for "foo" method documentation ("bar")). But, how to document a property (below, self.d)? ### class a(): def __init__( self ): self.d = 2 def foo( self ): "bar" b=a() pr

import in a class

2008-11-26 Thread TP
Hi everybody, Here is a file "test_import_scope.py": ## class a(): import re def __init__( self ): if re.search( "to", "toto" ): self.se = "ok!" def print_se( self ): print self.se a().print_se() ## When python executes this file, we obtain an error:

multiple breaks

2008-11-13 Thread TP
Hi everybody, Several means to escape a nested loop are given here: http://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-python According to this page, the best way is to modify the loop by affecting the variables that are tested in the loops. Otherwise, use exception:

script that parses command line, and execfile('')

2008-11-03 Thread TP
Hello, I have a script that uses the "optparse" package to parse the command line. For example: $ script.py --help # displays help about script.py Is this possible to call such a script with execfile('') once in the Python interactive shell? >>> execfile( 'script.py' ) I get errors because the

redirection in a file with os.system

2008-11-03 Thread TP
Hi everybody, The following code does not redirect the output of os.system("ls") in a file: import sys, os saveout = sys.stdout fd = open( 'toto', 'w' ) sys.stdout = fd os.system( "ls" ) sys.stdout = saveout fd.close() Whereas the following works: old_stdout = os.dup( sys.stdout.fileno() ) fd =

length of a tuple or a list containing only one element

2008-11-03 Thread TP
Hi everybody, I have a question about the difference of behavior of "len" when applied on tuples or on lists. I mean: $ len( ( 'foo', 'bar' ) ) 2 $ len( ( 'foo' ) ) 3 $ len( [ 'foo', 'bar' ] ) 2 $ len( [ 'foo' ] ) 1 Why this behavior for the length computation of a tuple? For my application, I p

Re: question about the textwrap module

2008-10-28 Thread TP
Gabriel Genellina wrote: > You may pre-process your text (stripping redundant whitespace) before > using textwrap: Thanks Gabriel for your answers! I finally have subclassed textwrap.TextWrapper. Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z (55l4('])" "W

question about the textwrap module

2008-10-27 Thread TP
Hi everybody, Recently, I have tried to improve the look of the printed text in command line. For this, I was compelled to remove redundant spaces in strings, because in my scripts, often the strings are spreading on several lines. For example, "aaa bbb" had to be transformed in "aaa bbb". I ha

redirection of standard output of a Python command to a Python variable

2008-10-27 Thread TP
Hi everybody, I try to find a quick way to redirect the standard output of a Python command (for example: print "message") to a python variable "foobar". Ok, in this simple example, I could do foobar = "message", but in fact 'print "message"' could be replaced by any Python function writing on sta

execute a function before and after any method of a parent class

2008-10-03 Thread TP
Hi everybody, I would like to be able to specialize an existing class A, so as to obtain a class B(A), with all methods of B being the methods of A preceded by a special method of B called _before_any_method_of_A( self ), and followed by a special method of B called _after_any_method_of_A( self ).

raw_input on several lines

2008-08-02 Thread TP
Hi everybody, When using raw_input(), the input of the user ends when he types Return on his keyboard. How can I change this behavior, so that another action is needed to stop the input? For example, CTRL-G. It would allow the user to input several lines. Thanks Julien -- python -c "print ''.

how to avoid line return when using python -c 'print "foo"'

2008-07-18 Thread TP
Hi everybody, All my problem is in the title. If I try: $ python -c 'print "foo",' It does not change anything, surely because the line return is added by "python -c". Thanks in advance Julien -- TP (Tribulations Parallèles) "Allez, Monsieur, allez, e

Re: interpretation of special characters in Python

2008-07-07 Thread TP
Peter Pearson wrote: > I don't understand exactly what you mean by "Sorry" I means: please forgive me for having said that it does not work with variables, because it is completely false. Thanks one more time Julien -- TP (Tribulations Parallèles) "Allez, Monsieur

Re: interpretation of special characters in Python

2008-07-07 Thread TP
It works perfectly. Indeed, one can read in the documentation concerning encodings: "Produce a string that is suitable as string literal in Python source code" -- TP (Tribulations Parallèles) "Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert). -- http://mail.python.org/mailman/listinfo/python-list

Re: interpretation of special characters in Python

2008-07-07 Thread TP
TP wrote: > So, the python print command *can* interpret these 4-character as a single > character. It would be odd if there were no possibility to do the same > thing when the characters are (i) stored in a python variable Sorry, it works when using variables. Try for example: col=&qu

Re: interpretation of special characters in Python

2008-07-06 Thread TP
om the environment variables. Does anybody know any way to re-interpret a string in Python? I have tried to play with "eval" (as in bash), but it does not yield anything. -- TP (Tribulations Parallèles) "Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert). -- http://mail.python.org/mailman/listinfo/python-list

Re: interpretation of special characters in Python

2008-07-06 Thread TP
Dennis Lee Bieber wrote: > Off-hand, I'd probably try first with: > > csi = "\033[" > > and then define your > > colorblackondarkblue = $csi"30;44m" Thanks for your answer. I have tried this slight modification, but it does not change anything on

interpretation of special characters in Python

2008-07-06 Thread TP
3[0m Why? What is the problem? Is there any solution? I really want to get my shell color variables. Thanks a lot -- TP (Tribulations Parallèles) "Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert). -- http://mail.python.org/mailman/listinfo/python-list