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 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

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 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

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

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 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

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. >>

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&#

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

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

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

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

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

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: 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

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: 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

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: 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

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=

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

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

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

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

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

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

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 `eval` code with `def`?

2017-05-28 Thread Peng Yu
Hi, I got the following error when I try to eval the following code with def. Does anybody know what is the correct way to evaluation python code that contains `def`? Thanks. $ cat ./main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: im

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://

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 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: 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

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

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

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

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

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-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: 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

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 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

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: 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

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
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 >&

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

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]

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

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

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

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

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

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

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

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

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

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

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 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

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

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.

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):

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

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/

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

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 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

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

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-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-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: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 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

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

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/__

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

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

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 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 match patterns like XX YY XX YY? (regex)

2010-08-07 Thread Peng Yu
Hi, Suppose that I have strings like the following test(a b)a b test(xy uv)xy uv ... I want to change them to test(a)a test(b)b test(xy)xy test(uv)uv ... The problem is that I don't know how to capture pattern that repeat itself (like 'a' and 'xy' in the example). I could use 'test\((\w+) (\w

Where is the help page for re.MatchObject?

2010-07-27 Thread Peng Yu
I know the library reference webpage for re.MatchObject is at http://docs.python.org/library/re.html#re.MatchObject But I don't find such a help page in python help(). Does anybody know how to get it in help()? >>> help(re.MatchObject) Traceback (most recent call last): File "", line 1, in Att

How to capture all the environment variables from shell?

2010-07-26 Thread Peng Yu
Hi, R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm not sure what it does when os module is imported. But it seems that os.environ doesn't capture all the environment variable from the shell. Could anybody let me know what is the correct way to inherent all the environment va

python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Peng Yu
This webpage http://www.python.org/dev/peps/pep-0008/ recommends the following. It looks to me that both styles are fine. Could anybody let me know what the rationale is behind this recommendation? - Use spaces around arithmetic operators: Yes: i = i + 1 submitted +

python terminology on classes

2010-07-26 Thread Peng Yu
Hi I'm still kind of confused about the terminology on classes in python. Could you please let me know what the equivalent terms for the following C++ terms? constructor destructor member function member variable virtual member function function I think that C++ "function" is equivalent to pyth

Where is a module usually installed?

2010-07-16 Thread Peng Yu
My Python is installed in the following location. ~/utility/linux/opt/Python-2.6.5/ I then installed SCons (http://www.scons.org/) using the command "python setup.py install", which install it at ~/utility/linux/opt/Python-2.6.5/lib/scons-2.0.0.final.0 sys.path doesn't have the above directory. I

Re: Is '[' a function or an operator or an language feature?

2010-07-16 Thread Peng Yu
On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: > On 7/16/2010 1:01 PM, Peng Yu wrote: >> >> I mean to get the man page for '[' like in the following code. >> >> x=[1,2,3] > > You might find my Python symbol glossary useful. > https://

Re: How to list all the python help topics that are capitalized?

2010-07-16 Thread Peng Yu
On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: > Peng Yu wrote: >> >> Hi, >> >> I see that there are help topics that are capitalized, which I think >> in general are related with languages syntax. I want to see the >> complete list of such help topics. Would

How to list all the python help topics that are capitalized?

2010-07-16 Thread Peng Yu
Hi, I see that there are help topics that are capitalized, which I think in general are related with languages syntax. I want to see the complete list of such help topics. Would you please let me know if there is a command to do so? >>> help('SUBSCRIPTS') Related help topics: SEQUENCEMETHODS1 >

Is '[' a function or an operator or an language feature?

2010-07-16 Thread Peng Yu
I mean to get the man page for '[' like in the following code. x=[1,2,3] But help('[') doesn't seem to give the above usage. ### Mutable Sequence Types ** List objects support additional operations that allow in-place modification of the object. Other mutable sequen

improving python performance by extension module (64bit)

2010-06-24 Thread Peng Yu
http://psyco.sourceforge.net/ The above package can improve python program on 32 bit library. But I need to run on 64 bit library. Is there any other module that can help improving the performance of python on 64 bit? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

Re: print line number and source filename

2010-06-23 Thread Peng Yu
On Tue, Jun 22, 2010 at 12:13 PM, Stephen Hansen wrote: > On 6/22/10 9:44 AM, Peng Yu wrote: >> Also, always importing the inspect module and getting the frame and >> accessing the lineno from the frame is not very convenient to type. Is >> there a shorter way to access

print line number and source filename

2010-06-22 Thread Peng Yu
I want to print filename and line number for debugging purpose. So far I only find how to print the line number but not how to print filename. import inspect print inspect.currentframe().f_lineno I found inspect.getsourcefile(), but I have to supply a class name to it. I have searched online, but

Why inspect.getsource() can not getsource for a class?

2010-06-22 Thread Peng Yu
Hi, It seems I don't completely understand how getsource works, as I expect that I should get the source code of class A. But I don't. Would you please let me know what I am wrong? $ cat main.py #!/usr/bin/env python import inspect class A: pass a=A() print inspect.getsource(a) $ ./main.py

Why 'open' is not a function according to inspect module?

2010-06-22 Thread Peng Yu
Hi, 'open' is not a function according to inspect module. But according to help(open), it is a function. Is there something wrong with inspect module? $ cat main.py #!/usr/bin/env python import inspect def hello(): print "Hello World!" return print inspect.isfunction(str) print inspect.isf

What is the difference between 'type' and 'class'?

2010-06-21 Thread Peng Yu
pydoc xrange says: Help on class xrange in module __builtin__: class xrange(object) python_2.6.5_library.pdf says: Objects of type xrange are similar to buffers Are type and class synonyms? It seems that they are at least according to some webpages that I read. But I'm not completely sure. Cou

Where is the help function defined?

2010-06-21 Thread Peng Yu
help(help) gives me the following explanation. ## Help on _Helper in module site object: class _Helper(__builtin__.object) | Define the built-in 'help'. | This is a wrapper around pydoc.help (with a twist). | | Methods defined here: | | __call__(self, *args, **kwds) |

python command line manual

2010-05-24 Thread Peng Yu
I mainly check online python manual. But I feel that it would be nice if there is command line manual available (just like perl command line manual). Could you please let me know if such command line manual available? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

How to show the current line number with pdb.set_trace()

2010-05-21 Thread Peng Yu
After starting pdb.set_trace(), python doens't show line number. Could you let me know how to print the number by default so that I know where the current line is? -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >