How to print a number as if in the python interpreter?

2012-07-06 Thread Peng Yu
Hi, In [2]: sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) Out[2]: 0. In ipython, I got the above output. But I got a different output from "print". Is there a way to print exact what I saw in ipython? ~/linux/test/python/man/library/math/fsum$ cat main.py #!/usr/bin/env python pr

pip fails to install packages on moutain loin (Mac OS 10.8.2)

2012-10-18 Thread Peng Yu
Hi, I installed Python using python-2.7.3-macosx10.6.dmg on my Mac OS 10.8.2. When try to use pip to install packages, I get the following message. Then the installation fails. gcc-4.2 not found, using clang instead I then create a link from /usr/bin/gcc to gcc-4.2. Then I run pip again, I get

How to access the document for __call__ from command line?

2012-10-18 Thread Peng Yu
Hi, reference.pdf from python document has the following description. It is not accessible from help() in the command line. Is there an alternative so that I can quickly access these class attributes or method names from the command line? object.__call__(self [, args... ]) Called when the instanc

How to print python commands automatically?

2012-11-08 Thread Peng Yu
Hi, In bash, set -v will print the command executed. For example, the following screen output shows that the "echo" command is printed automatically. Is there a similar thing in python? ~/linux/test/bash/man/builtin/set/-v$ cat main.sh #!/usr/bin/env bash set -v echo "Hello World!" ~/linux/test/

Re: How to print python commands automatically?

2012-11-09 Thread Peng Yu
> Is this what you want? > http://docs.python.org/2/library/trace.html I'm not able to get the mixing of the python command screen output on stdout. Is there a combination of options for this purpose? ~/linux/test/python/man/library/trace$ cat main1.py #!/usr/bin/env python def f(): print "Hel

Re: How to print python commands automatically?

2012-11-09 Thread Peng Yu
> Try with just --trace? > > > C:\ramit>python.exe -m trace test.py > C:\ramit\Python27\lib\trace.py: must specify one of --trace, --count, > --report, --listfuncs, or --trackcalls > > C:\ramit>python -m trace --trace test.py > --- modulename: test, funcname: > test.py(2): def f(): > test.py(5):

Why queue.empty() returns False even after put() is called?

2012-11-23 Thread Peng Yu
Hi, The empty() returns True even after put() has been called. Why it is empty when there some items in it? Could anybody help me understand it? Thanks! ~/linux/test/python/man/library/multiprocessing/Queue/empty$ cat main.py #!/usr/bin/env python import multiprocessing queue = multiprocessing.

The default locale of sorted()

2012-12-03 Thread Peng Yu
Hi, I'm not able to find the documentation on what locale is used for sorted() when the 'cmp' argument is not specified. Could anybody let me what the default is? If I always want LC_ALL=C, do I need to explicitly set the locale? Or it is the default? Regards, Peng -- http://mail.python.org/mail

python module development workflow

2012-04-11 Thread Peng Yu
Hi, It is confusing to me what the best workflow is for python module development. There is setup.py, egg. Also, pip, easy_install. Could any expert suggest an authoritative and complete guide for developing python modules? Thanks! Regards, Peng -- http://mail.python.org/mailman/listinfo/python

Re: python module development workflow

2012-04-11 Thread Peng Yu
On Apr 11, 10:25 am, John Gordon wrote: > In <2900f481-fbe9-4da3-a7ca-5485d1ceb...@m13g2000yqc.googlegroups.com> Peng > Yu writes: > > > It is confusing to me what the best workflow is for python module > > development. There is setup.py, egg. Also, pip, easy_install

Why variable used in list comprehension available outside?

2012-05-02 Thread Peng Yu
Hi, The following example demonstrates the variable 'v' used in the list comprehension is accessible out site the list comprehension. I think that 'v' should be strictly local. Does anybody know where this behavior is documented and why it is designed this way? ~/linux/test/python/man/library/__

When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-03 Thread Peng Yu
Hi, list(a_set) When convert two sets with the same elements to two lists, are the lists always going to be the same (i.e., the elements in each list are ordered the same)? Is it documented anywhere? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-04 Thread Peng Yu
On Thu, May 3, 2012 at 11:16 PM, Terry Reedy wrote: > On 5/3/2012 8:36 PM, Peng Yu wrote: >> >> Hi, >> >> list(a_set) >> >> When convert two sets with the same elements to two lists, are the >> lists always going to be the same (i.e., the elements

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-04 Thread Peng Yu
On Fri, May 4, 2012 at 6:21 AM, Chris Angelico wrote: > On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: >> Thanks. This is what I'm looking for. I think that this should be >> added to the python document as a manifestation (but nonnormalized) of >> what "A set ob

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-04 Thread Peng Yu
On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > On 5/4/2012 8:00 AM, Peng Yu wrote: >> >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico  wrote: >>> >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu  wrote: >>>> >>>> Thanks. This is what I

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-04 Thread Peng Yu
On Fri, May 4, 2012 at 6:12 PM, Cameron Simpson wrote: > On 04May2012 15:08, Peng Yu wrote: > | On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > | > On 5/4/2012 8:00 AM, Peng Yu wrote: > | >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico  wrote: > | >>&g

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-05 Thread Peng Yu
Hi Terry, Thank you for you detailed email. > If two collections are equal, should the iteration order be the same? It has > always been true that if hash values collide, insertion order matters. > However, a good hash function avoids hash collisions as much as possible in > practical use cases.

Re: When convert two sets with the same elements to lists, are the lists always going to be the same?

2012-05-05 Thread Peng Yu
> Documentation that takes ten pages to say something is just as bad as > documentation that leaves stuff out, because it's almost guaranteed > that it won't be read. That's the point. If a simple example (6 lines) can demonstrate the concept, why spending "ten pages" to explain it. My experience

Is there something like head() and str() of R in python?

2017-11-19 Thread Peng Yu
Hi, R has the functions head() and str() to show the brief content of an object. Is there something similar in python for this purpose? For example, I want to inspect the content of the variable "train". What is the best way to do so? Thanks. $ cat demo.py from __future__ import division, print_f

How to get the redirected URL only but not the actual content?

2017-12-01 Thread Peng Yu
Hi, Does anybody know how only get the redirected URL but not the actual content? I guess the request module probably should be used. But I am not sure how to do it exactly. Can somebody show me the best way to request (https://doi.org/10.1109/5.771073) and get the URL (http://ieeexplore.ieee.or

Re: How to get the redirected URL only but not the actual content?

2017-12-01 Thread Peng Yu
Where is `?reload=true` from? How to just get the redict URL that one would get from the browser? Thanks. > 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Anything similar to __END__ in perl

2017-12-07 Thread Peng Yu
Hi, perl has __END__ which ignore all the lines below it. Is there anything similar to __END__ in python? Thanks. -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

What is wrong with this regex for matching emails?

2017-12-17 Thread Peng Yu
Hi, I would like to extract "a...@efg.hij.xyz". But it only shows ".hij". Does anybody see what is wrong with it? Thanks. $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import re email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-z

How to edit a function in an interactive python session?

2017-12-20 Thread Peng Yu
Hi, R has the function edit() which allows the editing of the definition of a function. Does python have something similar so that users can edit python functions on the fly? Thanks. https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit -- Regards, Peng -- https://mail.pytho

Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Peng Yu
Hi, I see the following two lines are the same. But I'd like to find where ^ is documented via the help() function (I am not looking for the document in html)? Does anybody know? Thanks. s.symmetric_difference(t) s ^ t -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Why are both locals() and globals() set?

2017-12-22 Thread Peng Yu
Hi, The following example shows that both locals() and globals() are updated when x and f are defined. Shouldn't they be considered and global variable and functions only? Why does it make sense to set locals() as well? Thanks. $ cat ./main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=

Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Peng Yu
Where is it documented that __xor__ and ^ is the same as symmetric_difference? Thanks. BTW, I am using to Python 2, your help message is different from mine. Do you use Python 3? On Fri, Dec 22, 2017 at 9:41 PM, Dan Sommers wrote: > On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote: > &g

What is the meaning of @@?

2017-12-22 Thread Peng Yu
Hi, I only can find the doc for @. What does @@ mean in python? -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: What is the meaning of @@?

2017-12-24 Thread Peng Yu
See for example this file. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py On Sat, Dec 23, 2017 at 12:03 AM, Steve D'Aprano wrote: > On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: > >> Hi, I only can find the doc for @. What does @@ mean

Where is the usage of (list comprehension) documented?

2018-01-14 Thread Peng Yu
Hi, I see the following usage of list comprehension can generate a generator. Does anybody know where this is documented? Thanks. $ cat main.py #!/usr/bin/env python import sys lines = (line.rstrip('\n') for line in sys.stdin) print lines lines = [line.rstrip('\n') for line in sys.stdin] print

Re: Where is the usage of (list comprehension) documented?

2018-01-14 Thread Peng Yu
> When you use square brackets, you're creating a generator, as in your > second example. Your first example is a slightly different beast > called a "generator expression". If you search for that in the docs or > on the web, you'll find what you want. Thanks. Can the documentation be found by `he

Can utf-8 encoded character contain a byte of TAB?

2018-01-15 Thread Peng Yu
Hi, I use the following code to process TSV input. $ printf '%s\t%s\n' {1..10} | ./main.py ['1', '2'] ['3', '4'] ['5', '6'] ['7', '8'] ['9', '10'] $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import sys for line in sys.stdin

Re: Can utf-8 encoded character contain a byte of TAB?

2018-01-15 Thread Peng Yu
> Just to be clear, TAB *only* appears in utf-8 as the encoding for the actual > TAB character, not as a part of any other character's encoding. The only > bytes that can appear in the utf-8 encoding of non-ascii characters are > starting with 0xC2 through 0xF4, followed by one or more of 0x80 t

Where is _sre.SRE_Match?

2018-02-07 Thread Peng Yu
Hi, I see _sre.SRE_Match is returned by re.match. But I don't find where it is defined. Does anybody know how to get its help page within python command line? Thanks. >>> import re >>> m = re.match('a', 'abc') >>> print type(m) >>> _sre.SRE_Match Traceback (most recent call last): File "", lin

read Unicode characters one by one in python2

2018-02-24 Thread Peng Yu
Here shows some code for reading Unicode characters one by one in python2. Is it the best code for reading Unicode characters one by one in python2? https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Python -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-li

How to extract the raw bytes of the decoded unicode?

2018-02-24 Thread Peng Yu
Hi, I can extracted the encoded value as bytes. But is there a way to extracted the decoded value (for á, it is C1)? Thanks. $ cat ./dumpunicode.py #!/usr/bin/env python3 while True: c = sys.stdin.read(1) if c: print(c) print('0x' + ''.join(['%x' % x for x in reversed(byt

How to only get \n for newline without the single quotes?

2018-02-24 Thread Peng Yu
I would like to just get the escaped string without the single quotes. Is there a way to do so? Thanks. >>> x='\n' >>> print repr(x) '\n' -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: How to only get \n for newline without the single quotes?

2018-02-24 Thread Peng Yu
On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list wrote: > On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: > >> I would like to just get the escaped string without the single quotes. >> Is there a way to do so? Thanks. >> >>>>> x='\n&#

Re: How to only get \n for newline without the single quotes?

2018-02-24 Thread Peng Yu
On Sat, Feb 24, 2018 at 1:08 PM, Peng Yu wrote: > On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list > wrote: >> On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: >> >>> I would like to just get the escaped string without the single quotes. >>

How to access the help page of SRE_Pattern?

2018-03-05 Thread Peng Yu
Hi, >>> import re >>> prog=re.compile('[a-f]+') >>> help(prog) I can use the above command to access SRE_Pattern. But this involves the creation of an object of the class. I tried to directly access the class. But it does not work. Does anybody know if there is a way to directly access the class

How to get get_body() to work? (about email)

2023-03-19 Thread Peng Yu
Hi, https://docs.python.org/3/library/email.parser.html It says "For MIME messages, the root object will return True from its is_multipart() method, and the subparts can be accessed via the payload manipulation methods, such as get_body(), iter_parts(), and walk()." But when I try the following

ipython display figure

2021-04-13 Thread Peng Yu
Hi, https://www.fuzzingbook.org/html/Grammars.html I am trying to follow an example on the above page. But it does not show a figure. Could anybody let me know how to display the figure? $ ipython3 Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) Type 'copyright', 'credits' or 'license'

How to get the source code of python function being decorated?

2016-09-16 Thread Peng Yu
Hi, See the following example, I am not able to get the source code of the actual function that does the calculation of partial_ratio. Does anybody know what is the correct way of getting the source? /tmp$ ./main.py @functools.wraps(func) def decorator(*args, **kwargs): if args[0]

Where is the documentation for ','?

2016-09-16 Thread Peng Yu
Hi, I'm wondering where is the documentation for ',' as in the following usage. x = 1 y = 2 x, y = y, x I tried help(','). But there are too many ',' in it and I don't see in which section ',' is documented. Could anybody let me know? Thanks. -- Regards, Peng -- https://mail.python.org/mailma

Re: Where is the documentation for ','?

2016-09-16 Thread Peng Yu
ew__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T On Fri, Sep 16, 2016 at 9:13 PM, MRAB wrote: > On 2016-09-17 03:05, Peng Yu wrote: >> >> Hi, >> >> I'm wondering where is the documentation for ',' as in the following >&

Is there something similar to `set -v` of bash in python

2016-09-16 Thread Peng Yu
Hi, `set -v` in bash allows the print of the command before print the output of the command. I want to do the similar thing --- print a python command and then print the output of the command. Is it possible with python? -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: Where is the documentation for ','?

2016-09-16 Thread Peng Yu
OK. But it is documented somewhere in python doc? On Fri, Sep 16, 2016 at 9:48 PM, Lawrence D’Oliveiro wrote: > On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote: >> x, y = y, x > > It’s just syntactic sugar for > > (x, y) = (y, x) > -- > http

How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents. Here is my current code. $ cat main.sh #!/usr/bin/env bash # vim: set noexpandtab tabstop=2: set -v ./main.py Förstemann ./main.py Frédér8ic@ $ cat main.p

Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Peng Yu
> python -m trace -t yourprogram.py If I want to add some command in yourprogram.py to show the commands used it instead of calling trace from the command line, can it be done? -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Is the content available in the html doc available in help()?

2016-09-17 Thread Peng Yu
Hi, I want to get the same content as the html doc from help(). I am not sure if this is possible (as I tried help(inspect) which does not give the same content). Could anybody confirm if there is a way to get the same content from help()? Thanks. https://docs.python.org/2/library/inspect.html --

Re: Is the content available in the html doc available in help()?

2016-09-17 Thread Peng Yu
Sorry. I am still referring to python2. On Sat, Sep 17, 2016 at 8:45 PM, Lawrence D’Oliveiro wrote: > On Sunday, September 18, 2016 at 12:51:11 PM UTC+12, Peng Yu wrote: >> I want to get the same content as the html doc from help(). > > ldo@theon:~> pydoc3 inspect &g

Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Peng Yu
somehow settrace in one line and expect to get the trace function being called in the next line. So something like `set -v` in bash sounds not possible. Is it so? On Sat, Sep 17, 2016 at 5:28 PM, Ned Batchelder wrote: > On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote: >

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
./main.py Schöön $ ./main.sh Schoon >> Kouli >> >> On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >>> Hi, I want to convert strings in which the characters with accents >>> should be converted to the ones without accents. Here is my current >>> code. > >

Re: Is there something similar to `set -v` of bash in python

2016-09-18 Thread Peng Yu
On Sunday, September 18, 2016, Ned Batchelder wrote: > On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > > The manual says the following. > > > > "The trace function is invoked (with event set to 'call') whenever a > > new local scop

How to import all things defined the files in a module directory in __init__.py?

2016-09-21 Thread Peng Yu
Hi, Suppose that I have file1.py, ..., filen.py in a module directory. I want to import all the thing (or the ones available in the respective __all__) defined in each of the file by putting the following lines in __init__.py from file1 import * from filen import * However, I don't want to

Where is import defined in the source code? (python 2)

2016-09-21 Thread Peng Yu
Hi, I want know where import is defined in the source code. Is it implemented using __import__? -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Peng Yu
On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney wrote: > Peng Yu writes: > >> I want to import all the thing (or the ones available in the >> respective __all__) defined in each of the file by putting the >> following lines in __init__.py >> >> from file1 i

Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-22 Thread Peng Yu
On Thu, Sep 22, 2016 at 8:35 PM, Ben Finney wrote: > Peng Yu writes: > >> On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney >> wrote: >> > [Importing ‘*’ from a module] will also make the names in the code >> > impossible to automatically match against where the

Is there a way to change the closure of a python function?

2016-09-27 Thread Peng Yu
Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Peng Yu
On Tue, Sep 27, 2016 at 10:01 AM, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-

Is there an peekable similar to peekable but in additional allowing one to put some data to it?

2017-01-11 Thread Peng Yu
Hi, peekable from more-itertools only allow peeking an iterator. But sometimes, one may want to take a look at an element, manipulate it, then put it back to the iterator. Is there a class in python that can help do this? https://pypi.python.org/pypi/more-itertools/ -- Regards, Peng -- https://

OpenSSL error

2018-09-06 Thread Peng Yu
Hi, I got the following error. Does anybody know how to fix it? Thanks. $ pip Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/bin/pip", line 7, in from pip._internal import main File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python

How to print unicode characters with yaml.safe_dump()?

2016-05-31 Thread Peng Yu
Hi, The following code shows that "Michał" is printed differently for print(yaml.safe_dump(...)) and the direct print. Does anybody know how to use yaml.safe_dump() so that "Michał" will be printed as is. ~$ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabsto

Conversion between basic regular expression and extended regular expression

2018-11-17 Thread Peng Yu
Hi, I'd like to use a program to convert between basic regular expression (BRE) and extended regular expression (ERE). (see man grep for the definition of BRE and ERE). Does python has a module for this purpose? Thanks. -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

How to load cookies from a json input in python-requests?

2019-08-12 Thread Peng Yu
``` import requests s = requests.Session() import json s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin))) ``` I used the above command to load cookies from a json file. But I got the following error. Does anybody know how to fix the error? Thanks. ``` Traceback (most r

Is there a character that never appears in the output of zlib.compress?

2020-01-28 Thread Peng Yu
Hi, I'd like to tell what part is zlib.compress data in an input stream. One way is to use some characters that never appear in zlib.compress output to denote the boundary. Are there such characters? Thanks. -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

How to read the original data line by line from stdin in python 3 just like python 2?

2020-01-28 Thread Peng Yu
Suppose that I use this to read from stdin. But `line` contains decoded data in python 3. In python 2, it contains the original data. What is the best way to get the original data in python 3? Thanks. ``` for line in sys.stdin: ... ``` -- Regards, Peng -- https://mail.python.org/mailman/list

UnicodeEncodeError: 'ascii' codec can't encode character u'\ua000' in position 0: ordinal not in range(128)

2015-01-13 Thread Peng Yu
Hi, I am trying to understand what does encode() do. What are the hex representations of "u" in main.py? Why there is UnicodeEncodeError when main.py is piped to xxd? Why there is no such error when it is not piped? Thanks. ~$ cat main.py #!/usr/bin/env python u = unichr(40960) + u'abcd' + unich

How to install dtrx with pip?

2015-04-25 Thread Peng Yu
Hi, I get the following error when I try to install pip. Does anybody know what it is wrong and how to fix it? Thanks. ~/Downloads$ pip install dtrx Downloading/unpacking dtrx Could not find any downloads that satisfy the requirement dtrx Some externally hosted files were ignored (use --allow

How add class name to format of the logging module?

2011-10-12 Thread Peng Yu
Hi, The following attributes does not include the class name. Is there a way to add class name to the format string? Thanks! http://docs.python.org/library/logging.html#logrecord-attributes -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

How to generate error when argument are not supplied and there is no explicit defults (in optparse)?

2011-10-14 Thread Peng Yu
Hi, The following code doesn't give me error, even I don't specify the value of filename from the command line arguments. filename gets 'None'. I checked the manual, but I don't see a way to let OptionParser fail if an argument's value (which has no default explicitly specified) is not specified.

How to automatically get the indent level from code?

2013-03-16 Thread Peng Yu
Hi, I want to get the indent level within the code. For example, I want to print 1 within the while loop as the line is indented 1 level. Is it possible to get it within python? while 1: #print the level of indent, which is 1 here. -- Regards, Peng -- http://mail.python.org/mailman/listinfo

pprint defaultdict one record per line

2013-03-17 Thread Peng Yu
Hi, pprint can not print defaultdict one record per line. Is there some other convenient way in python to print one record per line? ~/linux/test/python/man/library/pprint/function/pprint$ ./main.py {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}

How to add the current dir to sys.path when calling a python file?

2013-03-17 Thread Peng Yu
Hi, man python says "If a script argument is given, the directory containing the script is inserted in the path in front of $PYTHONPATH. The search path can be manipulated from within a Python program as the variable sys.path." Instead I want to have the current directory inserted to the fron

Re: How to add the current dir to sys.path when calling a python file?

2013-03-18 Thread Peng Yu
On Mon, Mar 18, 2013 at 1:54 AM, Steven D'Aprano wrote: > On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote: > >> Hi, >> >> man python says "If a script argument is given, the directory >> containing the script is inserted in the path in front o

Re: How to automatically get the indent level from code?

2013-03-18 Thread Peng Yu
On Sun, Mar 17, 2013 at 1:23 AM, Mark Shroyer wrote: > I realize this isn't yet precisely what you're asking for, but look at the > inspect and ast modules: > > import ast, inspect > > def indent_level(): > lineno = inspect.currentframe().f_back.f_lineno > > with open(__fi

The usage of -m option of python

2013-03-18 Thread Peng Yu
Hi, I don't quite understand how -m option is used. And it is difficult to search for -m in google. Could anybody provide me with an example on how to use this option? Thanks! -m module-name Searches sys.path for the named module and runs the corresponding .py file as a scrip

How avoid installing directories match some pattern when using distutils.core setup?

2013-03-18 Thread Peng Yu
Hi, By default, setup.py will install everything in the source directory. I want mask some directories so that they will not be installed. Is there a way to do so in setup.py? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

using pandoc instead of rst to document python

2013-04-23 Thread Peng Yu
Hi, I'm wondering if it possible to use pandoc instead of rst to document python. Is there a documentation system support this format of python document? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

Re: using pandoc instead of rst to document python

2013-04-23 Thread Peng Yu
On Tue, Apr 23, 2013 at 5:40 PM, R. Michael Weylandt wrote: > On Tue, Apr 23, 2013 at 6:36 PM, Peng Yu wrote: >> Hi, >> >> I'm wondering if it possible to use pandoc instead of rst to document >> python. Is there a documentation system support this format of py

look-behind fixed width issue (package re)

2008-10-23 Thread Peng Yu
Hi, It seem that the current python requires fixed-width pattern for look- behind. I'm wondering if there is any newly development which make variable-width pattern available for look-behind. Thanks, Peng -- http://mail.python.org/mailman/listinfo/python-list

Re: look-behind fixed width issue (package re)

2008-10-24 Thread Peng Yu
> Most probably a backport to Python 2.6 or even 2.5 under a different > module name like re_ng wouldn't be too difficult to do for anybody that > needs the new functionality and knows a bit about building extension > modules. I did a google a search. But I don't find any document that describe it

how to match whole word

2008-07-15 Thread Peng Yu
Hi, The following code snippet is from /usr/bin/rpl. I would like the it to match a word, for example, "abc" in ":abc:". But the current one would not match "abc" in ":abc:". I tried to modify it myself. Would you please let me know what is the corrected way to do it? Thanks, Peng if opt

Re: how to match whole word

2008-07-16 Thread Peng Yu
On Jul 15, 10:29 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > Peng Yu wrote: > > Hi, > > > The following code snippet is from /usr/bin/rpl. I would like the it > > to match a word, for example, "abc" in ":abc:". But the current one > > would

python doc in command line

2008-07-16 Thread Peng Yu
Hi, Perl has a command line help perldoc. I'm wondering if python has a similar help command. Thanks, Peng -- http://mail.python.org/mailman/listinfo/python-list

How to match word boundary?

2008-07-22 Thread Peng Yu
Hi, I use r"\ba\b" to match "a". However, I can not use "\ba::\b" to match "a::b". I would like to match "a::" in "a::b", but not in "a:: b". That is, the character after "::" should be a alphanumeric character. Could you let me know how to do it and why "\b" would not work? Thanks, Peng -- http

Is there a metacharacter to match transitions between any two of a set of non intersected char classes?

2008-07-24 Thread Peng Yu
Hi, '\b' only match the boundary between alphanumerical char and nonalphanumerical char. I'm wonder if there is a generic metacharacter to match the boundary between any non intersected char set defined in regex and its complement. For example, I have a few non intersected char sets [a-zA-Z_0-9],

How to delete a line with re?

2008-08-17 Thread Peng Yu
Hi, I want to delete the line with abc in the following program. But the following program does not do what I want. Can somebody let me know how to do it? Thanks, Peng #!/usr/bin/python import re file="""abcd efg hijk lmn """ regex = re.compile("^abcd$", re.MULTILINE) print file, print "$" p

Exception as the primary error handling mechanism?

2009-12-31 Thread Peng Yu
I observe that python library primarily use exception for error handling rather than use error code. In the article API Design Matters by Michi Henning Communications of the ACM Vol. 52 No. 5, Pages 46-56 10.1145/1506409.1506424 http://cacm.acm.org/magazines/2009/5/24646-api-design-matters/fullte

Re: Exception as the primary error handling mechanism?

2010-01-01 Thread Peng Yu
On Thu, Dec 31, 2009 at 11:24 PM, Chris Rebert wrote: > On Thu, Dec 31, 2009 at 8:47 PM, Peng Yu wrote: >> I observe that python library primarily use exception for error >> handling rather than use error code. >> >> In the article API Design Matters by Michi Henning

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Peng Yu
On Sat, Jan 2, 2010 at 6:05 AM, Diez B. Roggisch wrote: > Peng Yu schrieb: >> >> On Thu, Dec 31, 2009 at 11:24 PM, Chris Rebert wrote: >>> >>> On Thu, Dec 31, 2009 at 8:47 PM, Peng Yu wrote: >>>> >>>> I observe that python library primar

Is there a method (similar to str() method in R) that can print the data structure in python?

2009-09-26 Thread Peng Yu
Hi, I am looking for a method in python that is similar to the function str() in R, if you are familiar with R, If you have no idea of R, what I want is to print the class information of an object and the values of its members. Overloading '__expr__' and '__repr__' then using 'print' can sort of

Why the file mode of .pyc files has x?

2009-09-26 Thread Peng Yu
Hi, It is strange that the file mode of .pyc files are changed to executable (x mode) after the corresponding .py files have been run. I have the follow python, which is compiled from source code by me. $ python --version Python 2.6.2 Should .pyc files have the x mode? Regards, Peng -- http://

Re: Why the file mode of .pyc files has x?

2009-09-26 Thread Peng Yu
On Sat, Sep 26, 2009 at 8:10 AM, Steven D'Aprano wrote: > On Sat, 26 Sep 2009 06:57:52 -0500, Peng Yu wrote: > >> Hi, >> >> It is strange that the file mode of .pyc files are changed to executable >> (x mode) after the corresponding .py files have been run.

Re: Is there a method (similar to str() method in R) that can print the data structure in python?

2009-09-27 Thread Peng Yu
On Sat, Sep 26, 2009 at 2:05 PM, Robert Kern wrote: > On 2009-09-26 09:32 AM, Peng Yu wrote: >> >> Hi, >> >> I am looking for a method in python that is similar to the function >> str() in R, if you are familiar with R, >> >> If you have no

Re: Is there a method (similar to str() method in R) that can print the data structure in python?

2009-09-27 Thread Peng Yu
On Sun, Sep 27, 2009 at 1:20 PM, Simon Forman wrote: > On Sun, Sep 27, 2009 at 12:14 PM, Peng Yu wrote: >> On Sat, Sep 26, 2009 at 2:05 PM, Robert Kern wrote: >>> On 2009-09-26 09:32 AM, Peng Yu wrote: >>>> >>>> Hi, >>>> >>>> I

Re: Why the file mode of .pyc files has x?

2009-09-28 Thread Peng Yu
On Mon, Sep 28, 2009 at 12:43 AM, greg wrote: > Peng Yu wrote: >> >> -rw--- 1 pengy lilab  29 2009-09-26 10:10:45 main.py >> -rwx-- 1 pengy lilab 106 2009-09-26 10:19:17 test.py >> -rwx-- 1 pengy lilab 339 2009-09-26 10:20:39 test.pyc > > Doesn&#

Re: Why the file mode of .pyc files has x?

2009-09-28 Thread Peng Yu
On Mon, Sep 28, 2009 at 8:22 AM, Steven D'Aprano wrote: > On Mon, 28 Sep 2009 17:01:40 +1000, Cameron Simpson wrote: > >> On 26Sep2009 10:24, Peng Yu wrote: | > >> [st...@sylar test]$ ls -l >> | > total 16 >> | > -rw-rw-r-- 1 steve steve  6 2009-0

Re: How to refer to class name and function name in a python program?

2009-09-28 Thread Peng Yu
On Sun, Sep 20, 2009 at 12:43 PM, Benjamin Kaplan wrote: > On Sun, Sep 20, 2009 at 12:43 PM, Peng Yu wrote: >> On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte >> wrote: >>> On Sep 20, 8:38 pm, Peng Yu wrote: >>>> Hi, >>>> >>>> I ha

How to jump out of nested 'for'-loops?

2009-09-28 Thread Peng Yu
Hi, I want some command to jump out of nested loop. I'm wondering what is the most convenient way to do so in python. for i in range(10): print "i = ", i for j in range(10): if i*10 + j == 50: print i*10 + j break # I want to jump out of the loops. Regards, Peng -- http://ma

  1   2   3   >