Re: How to exctract title of links
import htmllib, formatter, urllib
class x(htmllib.HTMLParser):
inanchor = True # indicates whether we are inside anchor element
def dump(self, tag, attrs):
#print tag,
for a, v in attrs:
if a in ['a', 'src', 'href']:
print v,
print
#def do_img(self, attrs):
#self.dump('img', attrs)
def start_a(self, attrs):
self.dump('a', attrs)
self.inanchor = True # yes now we are in anchor element
def handle_data(self,data):
if self.inanchor:
print data # lets us print the anchor element inner data
self.inanchor = False # we handled the anchor element data
# this is not a nice way, self.inanchor should be set false
# when is reached. try in end_a(self) ...
#def start_form(self, attrs):
#self.dump('form', attrs)
y = x(formatter.NullFormatter())
y.feed(urllib.urlopen('http://www.aquabase.org/fish/dump.php3').read())
y.close()
--
http://mail.python.org/mailman/listinfo/python-list
RE: Python 3: dict & dict.keys()
Stefan Behnel wrote: > Ethan Furman, 24.07.2013 20:31: > > On 07/24/2013 10:23 AM, Stefan Behnel wrote: > >> Peter Otten, 24.07.2013 08:23: > >>> Ethan Furman wrote: > > So, my question boils down to: in Python 3 how is dict.keys() different > from dict? What are the use cases? > >>> > >>> To me it looks like views are a solution waiting for a problem. > >> > >> They reduce the API overhead. Previously, you needed values() and > >> itervalues(), with values() being not more than a special case of what > >> itervalues() provides anyway. Now it's just one method that gives you > >> everything. It simply has corrected the tradeoff from two special purpose > >> APIs to one general purpose API, that's all. > > > > I started this thread for two reasons: > > > > 1) Increase awareness that using `list(dict)` is a cross-version > > replacement for `dict.keys()` > > > > 2) Hopefully learn something about when a view is useful. > > > > So far #2 is pretty much a failure. > > I think the question is: how else would you implement an interface that > doesn't restrict itself to returning a list? I mean, previously, the > following was totally inefficient in terms of memory: > > value in d.values() > > It now avoids creating an intermediate list copy of the values, thus > running with no additional memory overhead (well, a constant, ok, but > definitely not linear) and keeps users from resorting to the much more > unfriendly > > for v in d.itervalues(): > if v == value: > return True > else: > return False > > in order to achieve the same thing. You can now even efficiently do this > for items, i.e. > > (key, value) in d.items() > > That's equivalent to "d[key] == value", but uses a different protocol, > meaning that you don't have to make a copy of the dict items in order to > pass it into something that works on a set or iterable of 2-tuples (which > is a way more generic interface than requiring a dict as input). These > things chain much more cleanly now, without first having to explain the > difference between items() and iteritems() and when to use which. > > It's all about replacing the old copy-to-list interface by something that > is efficiently processable step by step. All of this started back when > iterators became a part of the language, then generators, and now dict > views. They may not be the hugest feature ever, but they definitely fit > into the language much better and much more cleanly than the old > copy-to-list way. > > Ask yourself, if they had been there in Python 1.x, would you even have > thought about making the iter*() methods a part of the language? Would you > really have wanted a shorter way to create a list of dict values than > list(d.values())? > > Stefan > I am still not clear on the advantage of views vs. iterators. What makes d.viewkeys() better than d.iterkeys()? Why did they decide not to rename d.iterkeys() to d.keys() and instead use d.viewkeys()? Is the iteration over a set operation on keys really that common a use case? Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Python 3: dict & dict.keys()
Terry Reedy wrote: > > On 7/24/2013 4:34 PM, Prasad, Ramit wrote: > > > I am still not clear on the advantage of views vs. iterators. > > A1: Views are iterables that can be iterated more than once. Therefore, > they can be passed to a function that re-iterates its inputs, or to > multiple functions. They support 'x in view' as efficiently as possible. > Think about how you would write the non-view equivalent of '(0,None) in > somedict.views())'. When set-like, views support some set operations. > For .keys, which are always set-like, these operations are easy to > implement as dicts are based on a hashed array of keys. Hmm, that is a change that makes some sense to me. Does the view get updated when dictionary changes or is a new view needed? I assume the latter. > > Q2: What is the advantage of views vs. lists? > > A2: They do not take up space that is not needed. They can be converted > to lists, to get all the features of lists, but not vice versa. > > > What makes d.viewkeys() better than d.iterkeys()? Why did they decide > > not to rename d.iterkeys() to d.keys() and instead use d.viewkeys()? > > This is historically the wrong way to phrase the question. The 2.7 > .viewxyz methods were *not* used to make the 3.x .xyz methods. It was > the other way around. 3.0 came out with view methods replacing both list > and iter methods just after 2.6, after a couple of years of design, and > a year and a half before 2.7. The view methods were backported from 3.1 > to 2.7, with 'view' added to the name to avoid name conflicts, to make > it easier to write code that would either run on both 2.7 and 3.x or be > converted with 2to3. > > A better question is: 'When 3.0 was designed, why were views invented > for the .xyz methods rather than just renaming the .iterxyz methods. The > advantages given above are the answer. View methods replace both list > and iterator methods and are more flexible than either and directly or > indirectly have all the advantages of both. > > My question is why some people are fussing so much because Python > developers gave them one thing that is better than either of the two > things it replaces? I personally am not "fussing" as existing functionality was preserved (and improved). I just was not clear on the difference. Thanks for all the detail and context. > > The mis-phrased question above illustrates why people new to Python > should use the latest 3.x and ignore 2.x unless they must use 2.x > libraries. 2.7 has all the old stuff, for back compatibility, and as > much of the new stuff in 3.1 as seemed sensible, for forward > compatibility. Thus it has lots of confusing duplication, and in this > case, triplication I work with 2.6 so no choice there... :) > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: RE Module Performance
Chris Angelico wrote:
> On Fri, Jul 26, 2013 at 5:07 AM, wrote:
> > Let start with a simple string \textemdash or \texttendash
> >
> sys.getsizeof('-')
> > 40
> sys.getsizeof('a')
> > 26
>
> Most of the cost is in those two apostrophes, look:
>
> >>> sys.getsizeof('a')
> 26
> >>> sys.getsizeof(a)
> 8
>
> Okay, that's slightly unfair (bonus points: figure out what I did to
> make this work; there are at least two right answers) but still, look
> at what an empty string costs:
I like bonus points. :)
>>> a = None
>>> sys.getsizeof(a)
8
Not sure what the other right answer is...booleans take 12 bytes (on 2.6)
>
> >>> sys.getsizeof('')
> 25
>
> Or look at the difference between one of these characters and two:
>
> >>> sys.getsizeof('aa')-sys.getsizeof('a')
> 1
> >>> sys.getsizeof('--')-sys.getsizeof('-')
> 2
>
> That's what the characters really cost. The overhead is fixed. It is,
> in fact, almost completely insignificant. The storage requirement for
> a non-ASCII, BMP-only string converges to two bytes per character.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
Ramit
This email is confidential and subject to important disclaimers and conditions
including on offers for the purchase or sale of securities, accuracy and
completeness of information, viruses, confidentiality, legal privilege, and
legal entity disclaimers, available at
http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Creating a Simple User Interface for a Function
CTSB01 wrote:
> On Thursday, July 25, 2013 3:19:27 PM UTC-4, Dave Angel wrote:
> > On 07/25/2013 12:03 PM, CTSB01 wrote:
> >
> > > I have the following code that runs perfectly:
> >
> >
> > > def psi_j(x, j):
> >
> > >rtn = []
> >
> > >for n2 in range(0, len(x) * j - 2):
> >
> > > n = n2 / j
> >
> > > r = n2 - n * j
> >
> > > rtn.append(j * x[n] + r * (x[n + 1] - x[n]))
> >
> > > print 'n2 =', n2, ': n =', n, ' r =' , r, ' rtn =', rtn
> >
> > >return rtn
> >
> > No it doesn't run perfectly. It'll get a syntax error on the print
> >
> > function call. That's assuming you're still using Python 3.3. You
> >
> > really need to start by specifying your environment, without making us
> >
> > look back through previous threads from you.
> >
> > > This code takes a string x = [0,1,1,1,2] for example
> >
> > That's not a string. A string would be like
> >
> > xx = psi_j("0abcd1234")
> >
> > Perhaps you mean list? And is it a list of integers, or of arbitrary
> >
> > numbers? Are there any constraints on the sizes or signs of those numbers?
> >
> > > (it must always begin with 0) and a parameter j, say 2, and outputs a
> > > string (x = [0, 1, 2, 2, 2,
> 2, 2, 3] in this example).
> >
> > > It does this in two steps: First it decomposes some number m into a
> > > multiple of j and a remainder.
> >
> > Only if you replace the / with //. Or just use the function divmod():
> >
> >n, r = divmod(n2, m)
> >
> > > Then it runs this decomposition through a function on the rtn.append
> > > line.
> >
> > > Notice that this has cj - 1 terms where c is the number of terms in the
> > > input string and j is the
> parameter. Normally, we would like it to be able to calculate cj terms.
> >
> > > This is an issue with the function that I am more than happy to put aside
> > > for the moment.
> >
> > > My key interest is to be able to make this program
> >
> > So far you have a function, not a program. If you put it in a text file
> >
> > and run it from python, it'll do nothing but display a syntax error
> >
> > message. And when you fix that, it'll just run without doing anything.
> >
> > usable for someone who has no knowledge of programming. In
> >
> > particular, I need some kind of user interface that prompts
> >
> > > the user to input a string (ideally just by putting in numbers in the
> > > form 011123334 for example)
> and a parameter,
> >
> > > and then displays the output sequence. This is essentially what the
> > > program already does but the
> idea is to make it usable
> >
> > > for even the most technologically disinclined. Ideally it would do this
> > > without needing to run
> Python at all.
> >
> > Then why are you asking on the Python forum? Or perhaps you mean
> >
> > without him knowing he's running Python? In that case, use a shebang
> >
> > line at the beginning, which will tell Linux to automatically invoke the
> >
> > specified program (or programming language in this case).
> >
> > > If anyone is able to make this happen in Python I would be eternally
> > > grateful.
> >
> > If we assume you're running Python 3.3 on Linux, and the user is willing
> >
> > to us the terminal, then how about parsing the string from the command
> >
> > line he types? You can access it as011123334 a string from sys.argv,
> >
> > and convert it to separate numbers. Of course as it stands now, you
> >
> > cannot tell whether the user wanted
> >
> >0,1,1,1,2,3,3,3,4
> >
> > or
> >
> >0, 111, 23, 3, 3, 4
> >
> > or something else.
> >
> > DaveA
>
> Sorry Dave, to answer each part of your response:
>
> 1) I decided to use Python 2.7, and I will be sure to specify this in all
> future threads.
> 2) It is a list of positive integers. In fact, it is always going to be a
> list of positive increasing
> integers.
> 3) You're right. What I meant was that if after running that bit of code I
> enter
> >>> x = [0,1,2,3,4,5]
> >>> psi_j(x,2)
> I will get output that matches my requirements.
> 4) Yes, sorry that's what I meant (if I understood correctly). I was told
> elsewhere that I might want
> to try using tkinter. Essentially I'm trying to create a user interface that
> allows the user to just
> type in a string 01112345 for example, and choose a parameter (say j=2) and
> then click a button to run
> the function. I'd like to be able to run send a .exe file that the user can
> just open up and use with
> no further setup.
Any UI will work whether graphical or command line. TK is a good choice if you
assume that the user
has Python installed. If you are planning to create an exe (Windows) then you
can probably
bundle any GUI library (wx/gtk/qt) but you might be limited by the support of
the exe creating
tool. I have never created an executable like this, so I am not sure.
>
> So on top of the user interface I would also it looks like need to determine
> how to make Python chang
RE: Python Script Hashplings
Devyn Collier Johnson wrote: > Thanks Matthew Lefavor! But specifically, why use "#!/usr/bin/env python3" > instead of > "#!/usr/bin/python3"? > > Mahalo, > > DCJ I believe this will work on Windows for Python 3.3+ and also with virtualenv. https://pypi.python.org/pypi/virtualenv Virtualenv is highly recommended as it lets you create isolated Python environments on a per project basis. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: dump a multi dimensional dictionary
cerr wrote:
> Hi,
>
> Can I somehow use pickle.dump() to store a dictionary of lists to a file?
> I tried this:
>
> >>> import pickle
> >>> mylist = []
> >>> mydict = {}
> >>> mylist = '1','2'
> >>> mydict['3'] = mylist
> >>> fhg = open ("test", 'w')
> >>> pickle.dump(fhg,mydict)
> Traceback (most recent call last):
> File "", line 1, in
> File "/usr/lib/python2.7/pickle.py", line 1370, in dump
> Pickler(file, protocol).dump(obj)
> File "/usr/lib/python2.7/pickle.py", line 203, in __init__
> self.write = file.write
> AttributeError: 'dict' object has no attribute 'write'
> >>> print mydict
> {'3': ('1', '2')}
>
> or should I just write my own dump function that can hanle thiS?
>
> Please advise!
>
> Thanks,
> Ron
I think you have the parameters for dump backwards.
According to API http://docs.python.org/2/library/pickle.html#pickle.dump
the format is: pickle.dump(obj, file, protocol=None)
Which means you need to use: pickle.dump(mydict, fhg)
Ramit
This email is confidential and subject to important disclaimers and conditions
including on offers for the purchase or sale of securities, accuracy and
completeness of information, viruses, confidentiality, legal privilege, and
legal entity disclaimers, available at
http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Jython and PYTHONSTARTUP
> Does Jython 2.5 honour the PYTHONSTARTUP environment variable? According
> to my testing, it doesn't.
>
> There used to be a page describing the differences between Jython and
> CPython here:
>
> http://www.jython.org/docs/differences.html
>
> but it appears to have been eaten by the 404 Monster.
Maybe the outdated version will help:
http://www.jython.org/archive/21/docs/differences.html
For your specific question I see this in the docs,
"""
The Interactive Startup File
When you use Python interactively, it is frequently handy to have some standard
commands executed every time the interpreter is started. You can do this by
setting an environment variable named PYTHONSTARTUP to the name of a file
containing your start-up commands. This is similar to the .profile feature of
the Unix shells.
This file is only read in interactive sessions, not when Python reads commands
from a script, and not when /dev/tty is given as the explicit source of
commands (which otherwise behaves like an interactive session). It is executed
in the same namespace where interactive commands are executed, so that objects
that it defines or imports can be used without qualification in the interactive
session. You can also change the prompts sys.ps1 and sys.ps2 in this file.
If you want to read an additional start-up file from the current directory, you
can program this in the global start-up file using code like if
os.path.isfile('.pythonrc.py'): execfile('.pythonrc.py'). If you want to use
the startup file in a script, you must do this explicitly in the script:
import os filename = os.environ.get('PYTHONSTARTUP') if filename and
os.path.isfile(filename):
execfile(filename)
"""
http://www.jython.org/docs/tutorial/interpreter.html?highlight=pythonstartup
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: emded revision control in Python application?
>I have an application that would benefit from collaborative > working. Over time users construct a "data environment" which is a > number of files in JSON format contained in a few directories (in the > future I'll probably place these in a zip so the environment is > contained within a single file). At the moment there is one individual > constructing the data environment, and me occasionally applying > corrections after being e-mailed the files. But in the future there > might be several individuals in various locations. > > As a minimum requirement I need to embed some sort of version control, > so that changes committed by one individual will be seen in the local > environments of the others. Some of the work involves editing graphs > which have restrictions on their structure. In this case it would be > useful for edits to be committed / seen in real time. The users will not > be particularly technical, so the version control will have to happen > relatively quietly in the background. > > My immediate thoughts are to (somehow) embed Mercurial or Subversion. It > would certainly be useful to be able to revert to a previous version of > the data environment if an individual does something silly. But I'm not > actually convinced that this is the whole solution for collaborative > working. Any advice regarding the embedding of a version control system > or alternative approaches would be appreciated. I haven't tried anything > like this before. The desktop application is written in Python (2.6) > with a wxPython (2.8) GUI. Given the nature of the application / data > the machines involved might be locally networked but without web access > (if this makes a difference). TIA. Why not just stick the configs (binary blob or JSON string) in something like a sqlite database and store that database centrally accessible[1]? Something like subversion might be overkill. A table like the following would work if you want to track each file separately: table_name( revision_number, file/config name, data, username, timestamp ). Otherwise, if you want to track "environments" and not files: table_name( revision_number, data, username, timestamp ). Where revision number can be a sequence used to track / change current configuration. I recommend storing each file separately in the database. [1] http://www.sqlite.org/faq.html#q5 Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: using SQLalchemy
> > We have a very chaotic database (on MySql) at the moment, with for > > I'm trying to use SQLalchemy and it looks absolutely great, but in > > general as a policy we don't use external dependencies.. > > That's a very foolish general policy, a lot of the power of python is in > the huge array of excellent third party libraries and frameworks, but > each to their own... That applies to Perl, Python, Java and probably most major languages. I do not know about you, but I do not want to be writing everything from scratch and language developers have better things to do than implementing a dozen (or more) major libraries like lxml and xlwt just to name a few. For that matter, I do not think mysqldb is a built-in Python package. :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: how to interact with Windows cmd?
> what I want to do is
> 1.open cmd
> 2.waiting for user's typing
> 3.when I type "dir"
> 4.print the result of "dir"
> 5.then I type some other commands, printing the result until I type
> 'exit'
>
> I used
> p=subprocess.Popen('cmd',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=s
> ubprocess.PIPE,shell=True)
> p=communicate('dir')
>
> it shows the first result but the problem is
> 1. it's too long so the cmd split the result with "more?", so result
> is not perfect
> 2. after this, I typed like "cd .." but I/O is already closed so I
> can't do another things..
>
> Is there any good way?
Not much experience with subprocess, but from what I have read
on here shell=True is usually bad. If you are trying to use
Python as a sort of bash replacement, you may want to take a
look at iPython http://en.wikipedia.org/wiki/Ipython.
Not Apple related!
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: How to safely maintain a status file
> Well "neat tricks" aside, I am of the firm belief that deleting files should > never be possible whilst they are open. This is one of the few instances I think Windows does something better than OS X. Windows will check before you attempt to delete (i.e. move to Recycling Bin) while OS X will move a file to Trash quite happily only tell me it cannot remove the file when I try to empty the Trash. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: lambda in list comprehension acting funny
> VERBOSE = True
>
> def function(arg):
> if VERBOSE:
>print("calling function with arg %r" % arg)
> process(arg)
>
> def caller():
> VERBOSE = False
> function(1)
>
> -
> Python semantics: function sees VERBOSE False
> Haskell semantics: function sees VERBOSE True
>>> def caller():
... VERBOSE = False
... function(1)
>>> def function(arg):
... if VERBOSE:
...print("calling function with arg %r" % arg)
...
>>> VERBOSE = True
>>> caller()
calling function with arg 1
I might be being OCD, but caller needs `global VERBOSE` for that to
work as you explain.
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: adding a simulation mode
> > Please do NOT catch BaseException, since that is the wrong thing to do. > > I would agree if you had said "in production code". > > If you are investigating why a third-party function is stopping your > interpreter, then catching BaseException may tell you that the code > is raising the wrong kind of Exception. Once you know what kind the > function is raising, you should catch only that particular excpetion > subclass. I would say the opposite. In production code usually I want it to recover, log as much information as I need (including sending any notifications), and NOT just die. In development, not catching the exception will give me a full trace back automatically. Why bother with trying to catch and print something when the interpreter will do it for me? Not to mention that removes any hassle of trying to catch the "right" exception or figuring out the best way to print it. I suppose if there are arguments on the exception that were not printed then I might want to catch it, but has been rare in my experience. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [Python] RE: How to safely maintain a status file
> >> Well "neat tricks" aside, I am of the firm belief that deleting files > should > >> never be possible whilst they are open. > > This is one of the few instances I think Windows does something better > > than OS X. Windows will check before you attempt to delete (i.e. move > > to Recycling Bin) while OS X will move a file to Trash quite happily > > only tell me it cannot remove the file when I try to empty the Trash. > While I was trained in the Unix way, and believe it is entirely > appropriate to delete an open file. Even if I my program is the opener. > It's just too handy to have temp files that disappear on their own. > > As opposed to periodically going to %TEMP% and deleting them manually. Gah. In my experience things that are "too handy" are usually breaking what I consider "right". That being said, I am not entirely sure what I think is "right" in this circumstance. I suppose it depends on if I am the person deleting or the person who is looking at a file that is being deleted. Or the user who just wants the stupid computer to just Work. I lean slightly towards the POSIX handling with the addition that any additional write should throw an error. You are now saving to a file that will not exist the moment you close it and that is probably not expected. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: lambda in list comprehension acting funny
> >> VERBOSE = True
> >>
> >> def function(arg):
> >> if VERBOSE:
> >>print("calling function with arg %r" % arg)
> >> process(arg)
> >>
> >> def caller():
> >> VERBOSE = False
> >> function(1)
> >>
> >> -
> >> Python semantics: function sees VERBOSE False
> >> Haskell semantics: function sees VERBOSE True
>
> def caller():
> > ... VERBOSE = False
> > ... function(1)
> def function(arg):
> > ... if VERBOSE:
> > ...print("calling function with arg %r" % arg)
> > ...
> VERBOSE = True
> caller()
> > calling function with arg 1
> >
> > I might be being OCD, but caller needs `global VERBOSE` for that to
> > work as you explain.
>
> That would be quite different from what Rusi is after.
>
> If you add `global VERBOSE` to `caller`, then there is only one
> variable named `VERBOSE` and what `function` does, depends on
> the most recent assignment to that variable.
>
> If you remove your `global VERBOSE`, then there are two
> variables by that name, one global and one local to `caller`.
> In that case, there is the question of which one `function`
> will use.
>
But that is not what Rusi writes.
"Python semantics: function sees VERBOSE False" <- function
will not see False without the use of global.
> The function `function` refers to a variable `VERBOSE` that
> isn't local. In some programming langauages, the interpreter
> would then scan the call stack at run-time, looking for a scope
> where that name is defined. It would find the local one in
> `caller`. This is known as "dynamic binding".
>
> Other interpreters use the `VERBOSE` that was in scope at
> the point in the program text where `function` was defined.
> In this case, that would be the global one. This is called
> "lexical binding".
>
> Some programming languages allow you to indicate on a per-
> variable basis whether you want dynamic or lexical binding.
>
> Python is firmly in the lexical camp. Dynamic binding is not
> available in Python, and never will be.
True and a good explanation, but not what I understood
Rusi to mean.
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: assertraises behaviour
> > import unittest
> >
> > class TestWithRaises(unittest.TestCase):
> > def test_first(self):
> > assert False
> >
> > def test_second(self):
> > print("also called")
> > assert True
> >
> > if __name__ == '__main__':
> > unittest.main()
> >
> > in this case also the second test is run even if the first fails..
>
> The reason for that is that the unit testing framework catches and
> handles the error. It calls both test functions in some unspecified
> order and logs the result. Calls to two separate test functions are
> thereby separated from each other. This is intentionally so, but I think
> you can also give the unit testing framework a flag that makes it abort
> after the first error. In no way will the exception escape from the
> unittest.main() call though, it is all caught and handled inside, also
> by intention.
>
>
> > But that's probably easy because we just need to catch exceptions for
> > every method call, so it's not exactly the same thing..
>
> I don't understand what you want to say here. I also don't understand
> what your problem in general is. I guess there are some expectations
> which are not satisfied, but you haven't explained those explicitly yet.
>
I think Andrea wants to do the same thing but with nose and not
unittest.
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: assertraises behaviour
> On 17/07/2012 18:49, Prasad, Ramit wrote:
> >>> import unittest
> >>>
> >>> class TestWithRaises(unittest.TestCase):
> >>> def test_first(self):
> >>> assert False
> >>>
> >>> def test_second(self):
> >>> print("also called")
> >>> assert True
> >>>
> >>> if __name__ == '__main__':
> >>> unittest.main()
> >>>
> >>> in this case also the second test is run even if the first fails..
> >>
> >> The reason for that is that the unit testing framework catches and
> >> handles the error. It calls both test functions in some unspecified
> >> order and logs the result. Calls to two separate test functions are
> >> thereby separated from each other. This is intentionally so, but I think
> >> you can also give the unit testing framework a flag that makes it abort
> >> after the first error. In no way will the exception escape from the
> >> unittest.main() call though, it is all caught and handled inside, also
> >> by intention.
> >>
> >>
> >>> But that's probably easy because we just need to catch exceptions for
> >>> every method call, so it's not exactly the same thing..
> >>
> >> I don't understand what you want to say here. I also don't understand
> >> what your problem in general is. I guess there are some expectations
> >> which are not satisfied, but you haven't explained those explicitly yet.
> >>
> >
> > I think Andrea wants to do the same thing but with nose and not
> > unittest.
> >
> > Ramit
> >
>
> Do what? Like Ulrich Eckhart I simply don't understand what she's
> getting at. Perhaps it's a problem with Englsh being a second language
> issue rather than Python itself. Thankfully I'm sure that everything
> will come out in the wash.
>
> --
> Cheers.
>
> Mark Lawrence.
I get the impression that nose stops running tests once any test
fails instead of running all tests and listing all the tests and
their pass/fail status (like unittest). Granted that is just what
I get from the context as I read it as I have no knowledge of nose.
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: shutil ignore fails on passing a tuple?
> >>> ipatterns
> ('*.txt', '*.hdf', '*.pdf', '*.png')
> >>> igf = shutil.ignore_patterns(ipatterns)
> >>> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
>
> Traceback (most recent call last):
> File "", line 1, in
> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
> File "C:\Python27\lib\shutil.py", line 138, in _ignore_patterns
> ignored_names.extend(fnmatch.filter(names, pattern))
> File "C:\Python27\lib\fnmatch.py", line 49, in filter
> pat=os.path.normcase(pat)
> File "C:\Python27\lib\ntpath.py", line 46, in normcase
> return s.replace("/", "\\").lower()
> AttributeError: 'tuple' object has no attribute 'replace'
>
> >>> igg = shutil.ignore_patterns('*.txt', '*.hdf', '*.pdf', '*.png')
> >>> ignorethat = igg(ddftopdir, os.listdir(ddftopdir))
> >>> ignorethat
> set(['Chi2.png', 'DTSdata.hdf', 'TST.hdf', 'BullNoseDiffs.png',
> 'DTSall.hdf', 'Symmetry.pdf'])
> >>>
>
> Why does it fail on passing in a tuple of ignore strings? I thought the ,
> (comma) is pretty much the tuple constructor (if that is the right word).
>
> How can I solve this? Is there a way to convert a tuple of strings in a form
> that will be accepted?
>
Untested, but I think it should work.
igf = shutil.ignore_patterns(*ipatterns)
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Finding duplicate file names and modifying them based on elements of the path
> > I am making the assumption that you intend to collapse the directory > > tree and store each file in the same directory, otherwise I can't think > > of why you need to do this. > > Hi Simon, thanks for the reply. It's not quite this - what I am doing > is creating a zip file with relative path names, and if there are > duplicate files the parts of the path that are not be carried over > need to get prepended to the file names to make then unique, Depending on the file system of the client, you can hit file name length limits. I would think it would be better to just create the full structure in the zip. Just something to keep in mind, especially if you see funky behavior. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: help
>('per1','persona1.1','pro1'),('per1','persona1.1','pro2'),('per1','persona1.1','pro3'),('per1','persona1.1','pro4'),('per1','persona1.1','pro5'),('per2','persona2.1','pro1'),('per2','persona2.1','pro2'),('per2','persona2.1','pro3'),('per2','persona2.1','pro4'),('per2','persona2.1','pro5'),('per2','persona2.2','pro1'),('per2','persona2.2','pro2'),('per2','persona2.2','pro3'),('per2','persona2.2','pro4'),('per2','persona2.2','pro5'),('per2','persona2.3','pro1'),('per2','persona2.3','pro2'),('per2','persona2.3','pro3'),('per2','persona2.3','pro4'),('per2','persona2.3','pro5'),('per2','persona2.4','pro1'),('per2','persona2.4','pro2'),('per2','persona2.4','pro3'
You can use ast.literal_eval if you add an enclosing () or [] in the string
(and add a finishing paren for the last tuple).
>the string is made with fors, using data from another file, and I need it as a
>tuplelist
If you are transferring this data (network/file) you may want to take a
look at pickle/json. If you are doing this to convert to/from a CSV then look at
the csv module. If you say what are you trying to do and why, someone on the
list might be able to recommend a better way to do this.
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: from future import pass_function
> No offence to all the well meaning participants here, but this looks like > trolling I thought Ranting Rick had sole dominion over trolling? Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Is Python a commercial proposition ?
> I work in financials and the majority of our apps are developed in C++ > and Java yet all the tools that startup, deploy and conduct rigorous > unit testing are implemented in Python or Shell scripts that wrap > Python scripts. > > Python definitely has its place in the enterprise however not so much > for serious stand alone app development. > > I'm starting to see Python used along side many statistical and > analytical tools like R, SPlus, and Mathlab for back testing and > prototype work, in a lot of cases I've seen quants and traders > implement models in Python to back test and if successful converted to > Java or C++. Maybe this is true in *your* experience but *my* experience is very different. I have seen Python modules become modules that end up rewritten in C for performance reasons but I consider that part of the power of Python and an argument *for* Python. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [Python] Re: PyPI question, or, maybe I'm just stupid
> > However, personally, I am not interested in all the details (typically > > found in "CHANGES.txt") but some (often implicit) information is > > sufficient for me: something like "major API change", "minor bug > > fixes". Thus, think carefully what you put on the overview page. > I see your point. I'm just lazy, I guess. I already put a description > of what I've changed into git, so why, I muse, must I also edit the > overview page separately? I was hoping there was an automatic way that > "setup.py sdist upload" could handle it for me. Even if you could include commit messages I would not recommend it. Commit messages are for developers of _your_ package not users. It is like leaving a memo (cough or message) for future developers. As a user, I want to know that you added a feature AAA. I do *not* want to know that in order to add AAA you also had to modify BBB and create CCC. Maybe you had to revert BBB because it conflicted with DDD and then you refactored some code and added/updated comments. Finally you managed to fix BBB (maybe also modifying DDD?) and so the feature AAA is now available. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.
> >> I would suggest you change the theme -- using Firefox 3.6 the page is > >> very difficult to read. > > > > Thanks for the report. Do you mind if I ask why you are using such an > > old version? > > (It looks fine with Firefox 14.0.1) > > > That version works for me -- I don't like upgrading to a new version of > bugs if I don't have to. ;) Why do you prefer to keep your old security holes? Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: why the different output in Eclipse and Python Shell?
> > my code in Eclipse:
> >
> > dict.fromkeys(['China','America'])
> > print "dict is",dict
> >
> > output: dict is
> >
> > my code in Python Shell:
> >
> > dict.fromkeys(['China','America'])
> >
> > output:{'America': None, 'China': None}
> >
> > Output in Python Shell is what i wanna,but why not in Eclipse?
> >
> >
>
> The Python Shell is an interactive debugger, and prints the repr() of
> expressions that you don't assign anywhere. I don't know Eclipse, but I
> suspect what you want to do is something like:
>
> print "dict is", repr(dict)
I think you mean
print "dict is", repr(dict.fromkeys(['China','America']))
Otherwise you are just printing the repr of the dict type
and not the dictionary created. I would really store the output and
then print it.
d = dict.fromkeys(['China','America'])
print "dict is", d
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: EXTERNAL: Re: missing python-config and building python on Windows
> On 7/31/2012 11:49 PM, Mark Hammond wrote: > > On 1/08/2012 10:48 AM, Damon Register wrote: > >> 1. though I have looked in a few readme files, I don't see instructions for > >> installing what I have just built using MSVC. Where can I find the > >> instructions for installing after building with MSVC? > > > > There is no such process. In general, you can just run directly from the > built tree. > That is a bummer. That makes me more curious about how the Windows > installer was made and how all the pieces were gathered together. > > > I'm afraid I don't know what python-config is. It appears it might be a > reflection of how Python > > was configured and build on *nix systems - if that is the case then it is > expected that one does not > > exist for Windows (as it doesn't use the *nix build chain). > which means, I guess, that mingw is barely supported if at all. > While it may be Windows, mingw/msys is a nice way to build many > programs that are unix oriented. I suppose that just for fun I > should try to build python on SuSE to see how it goes. > > >> 3. It seems that MSVC doesn't produce the .a library files needed for > >> linking > >> into a mingw built program. Do I have to do that fun trick to > >> create the > >> .a from the dll? > > > > I'm surprised MSVC *can* build .a files for mingw - but AFAIK, even if MSVC > could do that, I believe > > Python makes no attempt to build with support for linking into mingw > programs. > I don't know that MSVC can do this. The only process of which I am aware is a > two step process using pexports and dlltool to generate the .a file from a > dll. > One reason I was using the python.org installer is that it already had the > python27.a file. Now I am even more curious about what was used to build > python > and create that installer. > > The python.org installer provided all I needed for build most python dependent > apps with mingw until I ran into one that needed python-config. I suppose > that > if python-config does what I suspect it does (produce cflags and ldflags as > does pkg-config) then perhaps I could just fake it by replacing use of > python-config with what the cflags and ldflags should be for where I have > python. I have no knowledge about building Python but does this help? http://wiki.python.org/moin/Building%20Python%20with%20the%20free%20MS%20C%20Toolkit Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Is Python a commercial proposition ?
> I'm in stuck record mode here, but one of the things I really enjoy > about reading here is the way things do go off topic. IMHO makes for a > far more interesting experience. YMMV. +1 Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: attribute is accessed from Nonetype
> Also, please use the names correctly and consistently. The None object > (yes, there is only one) is not the same as a none object. And there is > no standard type called Nonetype. To be fair, this is not very clear to a beginner. >>> len(None) # Python 2.6 TypeError: object of type 'NoneType' has no len() Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Calling Values
> def func1(): > > num1=10 > > num2=20 > > print "The Second Number is:",num2 > > return > > > def func2(): > > func1() > num3=num1+num2 > > num4=num3+num1 > > print "New Number One is:",num3 > > print "New Number Two is:",num4 > > > This works. Even you can incoportate some conditionals over func1() in func2() > and run. This does not work. Python does not get "compiled" in the same manner as other languages (C, Java etc). Since you never call func2(), there is no error. Once you try calling func2() you will see it does not work. func1() does work. The Second Number is: 20 Traceback (most recent call last): File "subha.py", line 24, in func2() File "subha.py", line 15, in func2 num3=num1+num2 NameError: global name 'num1' is not defined > My question can I call its values of func1() too? > What it is the big deal in experimenting we may come up with some new code or > a new need? It is not a big deal, that is how you learn. You are just writing code that neither works nor really shows enough to tell us why or what you are trying to do. Not much I can do to guide or help you because I am completely lost at your goal. The best I can do at the moment is say. func2 will not work. You could return num1 and num2 from func1() and then it would work. def func1(): num1=10 num2=20 print "The Second Number is:",num2 return num1, num2 def func2(): num1, num2 = func1() num3=num1+num2 num4=num3+num1 print "New Number One is:",num3 print "New Number Two is:",num4 func2() Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
[email protected]
> > I also tend to blame M$ (Outlook and variants) for this tendency to > > quote everything and top-post -- Outlook makes it almost impossible > > to do a trim&interleave response style. > > I that Outlook & Co are guilty. That and the fact that few people even > think about this. Nonsense, I post only from Outlook. You can do it and it is not hard. It is just requires a little effort. Top posting makes more sense in a corporate setting for a couple reasons. Seeing the exact email trail rather than what someone considers "relevant" context can be very useful. Not to mention that frequently corporate email is more like slow instant messaging; I need less context (e.g. conversation history) and get all the information I need from what the sender is writing. I find inline (and to a lesser extent bottom) posting to be a mixed bag. Some people do it well and it is easy to read, but there are others who do not make it as easy (for me) to read. Lots of posts are not trimmed enough, or trimmed too much. I am not advocating top-posting. I just think that different styles are good for different cases/environments. Blame the person, not the application for having poor habits and/or being inconsiderate of the community. :) Ramit P.S. Ironically, I do blame Outlook for making it hard (impossible?) to find/see the 80 char boundary. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [ANNC] pybotwar-0.8
>Look you are the only person complaining about top-posting. >GMail uses top-posting by default. >I can't help it if you feel irritated by it. He is most certainly not the only person to feel irritated nor even the only person who has requested you not to top post. He does happen to be the most persistent though. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [ANNC] pybotwar-0.8
> I'll be using Google Groups (hopefully it won't top-post by default) to post > stuff. Thanks for not top-posting. Even if it is the default, it is not difficult to change. :) Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
[email protected]
Ulrich Eckhardt wrote: > A good tool would reduce the effort and guide users, like e.g. giving > them a hint if they leave the whole mail they're replying to as copy. > Several corporate email solutions (like MS Outlook/Exchange) put very > little emphasis on communication efficiency but only on eye-candy > features. Their popularity and the resulting influence on people has > caused decay in average communication culture, and that is what I blame > them for. True, but it is by no means impossible or very difficult. It just requires some effort. I blame the user more and the software less because of quotes like below. [ Not Ulrich ] > GMail uses top-posting by default. [ Back to Ulrich ] > BTW: You omitted the attribution line for the text you quoted, whom do > you blame for that? That said, "Nonsense" is a strong enough word to > start a flamewar... not nice. Fair enough. I typically leave off attribution because I would rather to discuss things with quotes instead of he-said and she-said. The focus should be on the idea/conversation and less about attributing "blame" to someone (and it is invariably more often negative attribution than positive). If attribution is preferred, I suppose I could always add it back in. Ironically, this is one of the things I wish Outlook was better about. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: help with simple print statement!
Willem Krayenhoff
Any idea why print isn't working here?
I tried restarting my Command prompt. Also, print doesn't work inside a class.
--
Best Wishes,
Bruce
C: 604-441-5791
My Availability
Just as a note, this is a usenet group that can be accessed via email; a good
portion of the people on the list does not receive attachments and images. HTML
is also a bad format as it mangles code so please post in plain text and
copy/paste from the command line instead of using screenshots. It will be easy
for us to run your code if necessary to reproduce the results.
Now on to your problem. You are using Python 3 where print was turned from a
statement into a function. You need to use the following instead.
print('34ki')
print(6)
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: How to print something only if it exists?
[email protected] wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > > I know I could simply use an if but ultimately there may be more > elements of fld in the print and the print may well become more > complex (most like will be formatted for example). Thus it would be > good if there was some way to say "print this if it exists". You can use an inline if-else statement. print day, fld[1], balance, fld[2] if len(fld) >= 3 else '' Ramit -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Comparing strings from the back?
Dwight Hutto wrote: > Why don' you just time it,eit lops through incrementing thmax input/ What? Without context I have no idea what this means. Ramit -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: pythonOCC examples doesn't work?
Dwight Hutto wrote: [snip] > On Wed, Sep 12, 2012 at 3:37 AM, Mark Lawrence > wrote: [snip] > Others would be able to see this for themselves but > > you insist on sending email without context. Please don't do this. > > How are my emails without context? I'm referring the OP to the docs, > as well as posts related to their question. It goes to use google, and > RTFM, and putting it politely to them. > I have noticed that you do not always quote what you are talking about. Sometimes I can guess or look at another message and see what you are talking about, but not always. This list philosophy seems to be "quote what is relevant and trim what is not". Not on a "go lookup the previous message to find context". > I could summarize, but they have to do the real reading. I'm not > researching this, and if I was, I'd charge for the time. This is to > show that things can get complex if you don't use google, or read the > docs. Context is not the same as explaining absolutely everything. It means that I, the reader, can see *what* you are talking about and what you are responding *to*. I do agree with the stance not to spoon feed OP(s). > > Why does the OP keep asking here, when there are answers out there. > especially on the pywin list, which Windows users are usually referred > to. I was not aware that Windows users were "usually" referred anywhere. Most referrals are on a case-by-case basis as many problems or questions from Windows Python developers are Python questions and not specific to pywin. > > Please point out what's out of context. The links and references place > it into context if the OP finds them useful, and I believe I searched > well for them. > > Would the OP like to tell me I wasn't helpful? Because now they're > probably on a search to figure out how to make these compatible, which > means more questions, and more reading. Nobody is claiming you are not helpful. I appreciate your effort, I just do not always know what is going on in a thread especially if I see the thread jump to something I can contribute to but now have no context with which to help. Not to mention that the archive for this list is searchable. Your answer is much more useful for future searchers if you leave some context for someone reading this. [snip] > > Let's not argue about this, I was pointing them to what I saw as the > best possible resources to overcome his current problem, and it was > all in context of the conversation as far as I'm concerned. > It is in context of the "thread", but the context of the "conversation" was lost. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Which Version of Python?
Ramchandra Apte wrote: > On Wednesday, 12 September 2012 14:11:56 UTC+5:30, Ramchandra Apte wrote: > > On Wednesday, 12 September 2012 14:04:56 UTC+5:30, alex23 wrote: > > > On 12 Sep, 16:31, Mark Lawrence wrote: > > > > Perhaps this will sway youhttp://docs.python.org/dev/whatsnew/3.3.html > > > > There is no longer an equivalent document for the Python 1.x or 2.x > > > > series of releases. > > > Perhaps not for 1.x but the 2.x series is still covered: > > > http://docs.python.org/dev/whatsnew/index.html > > > Actually, 1.6 is included here: > > > http://www.python.org/download/releases/1.6.1/ > > I think he meant the length of the document. > Sorry, Mark must have meant theres no "What's New" document of the same length > (its very long). Would you mind trimming your responses of blank lines? The double line spacing makes it difficult to read. I know that it may be google groups that is doubling line spaces but it would help if you could remove the extra lines that you can when replying (as I have done above). Thanks, Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Comparing strings from the back?
Dwight Hutto wrote: > On Thu, Sep 13, 2012 at 5:17 PM, Mark Lawrence > wrote: > > On 13/09/2012 21:34, Joshua Landau wrote: > >> > >> On 13 September 2012 20:53, Mark Lawrence > wrote:acci sequence > >> > >>> On 13/09/2012 19:39, Prasad, Ramit wrote: > >>> > >>>> Dwight Hutto wrote: > >>>> > >>>>> Why don' you just time it,eit lops through incrementing thmax input/ > >>>>> > >>>> > >>>> What? Without context I have no idea what this means. > >>>> > >>> > >>> You're wasting your time, I've been described as a jackass for having > >>> the > >>> audacity to ask for context :) > >> Mark, Sometimes it is the style in which something is asked, and not what specifically is asked. ;) > >> > >> > >> I'm pretty sure you are in the wrong, acting as if what he said didn't > >> make > >> sense! Just read it, he obviously was telling you to time it, as eit lops > >> are inside thmax input/ which, as you should know if you *bothered to read > >> the thread*, is incrementing. > >> > >> > >> "don'" is short for "don't", by the way. > > > > I do grovellingly apologize for my appalling breach of netiquette. I am of > > course assuming that the rules have changed and that it's now my > > responsibility to wade back through maybe a couple of hundred responses on a > > long thread to find the context. > I also guess that I'm never going to > > achieve my ambition of being a pot smoking hippy CEO of a web development > > company :( > > -- > > Cheers. > Cheers usually implies you're an alcoholic pressing buttons, with the > half of rest of the coders on the net. Dwight/David: Not necessarily true if you happen to be from the UK (or maybe just England). It seems to be a cultural signature equivalent to "Thanks"--at least in the UK (not sure about other places). [snip] Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: pythonOCC examples doesn't work?
Dwight Hutto wrote: > Chris Angelico wrote: > > honest. How do you feel? Interesting... > > > Um, I guess like an inconsiderate bandwidth hog, but from now on I'll > trim more text. > > First it was too little, and now it's too much. It is a fine line to walk and nobody does it perfectly all the time. We just attempt our best. > I just tend to cut out some or all depending on the scope of the conversation. > > If I just hit reply all, and send it out, it's not intentionally to > use all of the text, and utilize the extra space, it's just a > response. > > If the conversation is kind of just a few people, then I trim pretty > much everything, which apparently set a guy name mark off, who I was > polite to, but I'm not going to get slammed for a few simple posting > mistakes, and more than likely a few of his aliases, or the group he > tends to cheer up with. Sorry, I did not mean to "slam" you by any means. I was just notifying you of the list's commonly agreed upon etiquette and requesting future posts to attempt to adhere to that. > > It's just a mailing list, lighten up because mistakes in posting will > happen, even by accident. > It's just a mailing list, lighten up because a few people trying to help improve your communication to the rest of the group may come off unintentionally as being "slammed" by the community. :) This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Comparing strings from the back?
Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 4:20 AM, alex23 wrote: > > On Sep 14, 6:04 pm, Dwight Hutto wrote: > >> > Using foreign names derogatively is a common tactic of the racist. > >> > >> Not really. But nice spin on my pun to make me look bad. > > > > It actually *is* common behaviour of racists. > > > > Not if there name is ramit. What if your name was john? I'd say I'll > be right back, I have to go take a crap on the john. It's a joke about > a name, not where it originates. Okay, so maybe not racist but instead offensive juvenile humor? I suppose that is better... > > >> It's similar to if I said, this is real 'queer' of you to do ya big > >> pansy, and next you'll be calling me a homophobe. Um, yes! You are using 'queer' and 'pansy' as a derogatory comparison which falls under the definition for homophobia. "Homophobia is a range of negative attitudes and feelings toward homosexuality or people who are identified or perceived as being lesbian, gay, bisexual or transgender (LGBT). Definitions refer variably to antipathy, contempt, prejudice, aversion, irrational fear, and hatred." ~ First two sentences on Wikipedia > > > > Well, *yes*. Because your choice of that terminology as derogatory > > shows you view it as derogatory. > > No it was a loose analogy to show that he's just trying to use > anything he can say to slam me, and everyone can know it wasn't meant > as racist. Since I was unsure myself if you were trying to be offensive or racist, I would disagree with "everyone can know it wasn't meant as racist". > > >> Try harder, because no one would ever believe I was a racist, and if > >> they did, it's an uninformed decision based off of cherry picken > >> phrases out of context. > > > > Oh, so *now* context is important. > > Never said it wasn't. The whole conversation to me is the context, and > the OP usually follows it, and that's who it is usually intended for. > [ snip ] This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Decorators not worth the effort
Jean-Michel Pichavant wrote:
[snip]
> Ultimately, the goal is to have something like
>
> @timeout(2)
> def doAction1
>
> @timeout(4)
> def doAction2
[snip]
> Here's Steven example:
>
> # Untested!
> def timeout(t=15):
> # Decorator factory. Return a decorator to actually do the work.
> if FPGA:
> t *= 3
> def decorator(func):
> @functools.wraps(func)
> def inner(self, timeout):
> self.sendCmd("bootMe", timeout=t)
> return inner
> return decorator
>
> I can assure you, that for some python users, it's is not easy to understand
> what it does, this function returning a function which returns another
> (wrapped) function. It requires some effort.
>
I think it would help if it was renamed to set_timeout. And I would
not expect the Python user to need to understand how it *works*, just
to recognize what it *does* when it is used. I may not understand list's
sort method internals (beyond the use of timsort), but I know how to
use it to sort a list as I want. That is usually all I need.
For example, your colleagues just need to understand that the below
decorator is setting a timeout for the function.
@set_timeout(min=15)
def some_function():
'''blah'''
One minor note, the style of decorator you are using loses the docstring
(at least) of the original function. I would add the @functools.wraps(func)
decorator inside your decorator.
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: How to limit CPU usage in Python
Paul Rubin wrote: > Rolando Cañer Roblejo writes: > > Is it possible for me to put a limit in the amount of processor usage > > (% CPU) that my current python script is using? Is there any module > > useful for this task? > > One way is check your cpu usage once in a while, compare with elapsed > time, and if your % usage is above what you want, sleep for a suitable > interval before proceeding. > > Tim Roberts: reasons to want to do this might involve a shared host > where excessive cpu usage affects other users; or a computer with > limited power consumption, where prolonged high cpu activity causes > thermal or other problems. The problem is that checking the CPU usage is fairly misleading if you are worried about contention. If your process takes up 100% of CPU and nothing else needs the resource, does it matter? I would not want to sleep *unless* something else needs the resource. Of course, there might be a good/easy way of checking usage + contention, but I am unaware of any off the top of my head. On *nix you should just set the appropriate nice-ness and then let the OS handle CPU scheduling. Not sure what you would do for Windows--I assume OS X is the same as *nix for this context. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Redirecting STDOUT to a Python Variable
Hans Mulder wrote: > On 22/09/12 23:57:52, [email protected] wrote: > > To capture the traceback, so to put it in a log, I use this > > > > import traceback > > > > def get_traceback(): # obtain and return the traceback > > exc_type, exc_value, exc_traceback = sys.exc_info() > > return ''.join(traceback.format_exception(exc_type, exc_value, > exc_traceback)) > > This could be coded more succinctly as > > import sys, traceback > > def get_traceback(): # obtain and return the traceback > return ''.join(traceback.format_exception(*sys.exc_info())) Why not just use? return traceback.format_exc() > > > Suppose I have a script run by the scheduler, this captures the traceback > form any problems and emails them. > > > > if __name__ == '__main__': > > try: > > Runs_unattended() > > except: > > send_mail(send_from = yourEmailAddress, > > send_to = [ yourEmailAddress ], subject = 'Runs_unattended', > > text = '%s' % get_traceback(), > > files = [], server=yourLocalSMTP) > > Errhm, '%s' % get_traceback() is equiavalent to get_traceback() > How about: > > if __name__ == '__main__': > try: > Runs_unattended() > except: > send_mail(send_from = yourEmailAddress, > send_to = [ yourEmailAddress ], > subject = 'Runs_unattended', > text = get_traceback(), > files = [], > server=yourLocalSMTP) > This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: One of my joomla webpages has been hacked. Please help.
? G??ee? wrote: > I shouldn't have asked about Joomla here, or even about Python embedding > within Joomla cms. I was under the impression that the latter was relevant to > ask here but it seems it isnt. > > My bad, let's just close this thread so i don't waste anyone's time. Now when/if you get Joomla to run Python code and have a problem with *Python* code/coding, feel free to come back and ask questions on that. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: For Counter Variable
Tim Chase wrote: > [snip] though I'm minorly miffed that > enumerate()'s starting-offset wasn't back-ported into earlier 2.x > versions and have had to code around it for 1-based indexing; either > extra "+1"s or whip up my own simple enumerate() generator). Starting offset is in Python 2.6, unless you meant earlier than 2.6. >>> for idx, x in enumerate( xrange(5), 10 ): ... print idx, x ... 10 0 11 1 12 2 13 3 14 4 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Capitalization for variable that holds a class
Dennis Lee Bieber wrote: > Sent: Sunday, September 23, 2012 11:53 AM > To: [email protected] > Subject: Re: Capitalization for variable that holds a class > > On Sun, 23 Sep 2012 16:48:38 +0100, Joshua Landau > declaimed the following in > gmane.comp.python.general: > > > Simple question: > > > > [myClass() for myClass in myClasses] > > vs > > [MyClass() for MyClass in myClasses] > > > > The recommended naming scheme for Python is that class DEFINITIONS > begin capitalized. Instances, methods/attributes, functions begin > lowercase. > > I abstain from the argument about camel-case vs _ (Ada "pretty > printers" automatically capitalize at _, so _ is common in Ada) > > class MyClass(object): > def myMethod(self): Are you (the OP) using Python 2 or 3? In python 2 list comprehensions leak; if you use MyClass as the list comprehension variable name it will overwrite the MyClass class definition (if it exists). >>> class MyClass(object): ... pass ... >>> print MyClass >>> _ = [ MyClass for MyClass in xrange( 5 ) ] >>> print MyClass 4 Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: A little morning puzzle
Dwight Hutto wrote: > > Ergo: 'enumerate()' is the correct suggestion over manually > > maintaining your own index, despite it ostensibly being "more" code > > due to its implementation. > > But, therefore, that doesn't mean that the coder can just USE a > function, and not be able to design it themselves. So 'correct > suggestion' is a moot point. > Can you rephrase your first sentence? I am not sure what you mean. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Fastest web framework
Andriy Kornatskyy wrote: > Try to see 'Hello World' benchmark as an answer to the question how effective > is the framework inside... > > If computer X boots faster than Y, it means it is more effective in this > particular area. > > If a sportsman runs a distance 1 second faster than other, he got a medal (it > is not quite adequate to say if I load sportsman with 50 kilo bag he will not > run that fast... just try split the concerns). > > Thanks. > > Andriy > Not really, it depends on what each computer is doing during boot. To switch to the sportsman analogy, if sportsman A has to run 1 mile and along the way pick up 1 lb/kg every .1 mile while sportsman B has to pick up all the weight at the start. It is conceivable that sportsman A runs completes the run in 10 minutes while sportsman B runs the time in 9 minutes. Sportsman A might run the first .1 miles faster (sportsman A "boots" faster, but that is most likely less important than the overall long-term/real-world time to complete the task. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: data attributes override method attributes?
Terry Reedy wrote: > On 9/25/2012 4:07 PM, Ian Kelly wrote: > > On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy wrote: > >> On 9/25/2012 11:03 AM, Chris Angelico wrote: > >>> Instance attributes override (shadow) class attributes. > >> > >> > >> except for (some? all?) special methods > > > > Those names are shadowed too. If you call foo.__len__() and the name > > is bound on the instance, it will call that function preferentially. > > It's just that when the special Python machinery calls the method, it > > skips the instance and goes straight to the class. > > I added "Ian Kelly reminds me that instance.__xxx__ is only skipped by > the internal machinery and not by direct accesses in user code. In the > other hand, docs, official or otherwise, are filled with things like > 'len(a) calls a.__len__', so I think something should be said that > giving instances special method attributes does not have the effect one > might expect." > > to the issue. > Just to make sure I am following, if you call foo.__len__() it goes to the instance code while if you do len(foo) it will go to class.__len__()? If so, why? This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: regular expression : the dollar sign ($) work with re.match() or re.search() ?
iMath wrote: > Sent: Wednesday, September 26, 2012 2:39 AM > To: [email protected] > Subject: regular expression : the dollar sign ($) work with re.match() or > re.search() ? > > I only know the dollar sign ($) will match a pattern from the > end of a string,but which method does it work with ,re.match() or re.search() > ? You can try this on the interactive interpreter. >>> re.match('hi$', 'xihi') >>> re.search('hi$', 'xihi') <_sre.SRE_Match object at 0x13FF7100> Although, I think match does not work since match only starts searching at the start of the string while search looks for the pattern anywhere in the string. >>> re.match('x.hi$', 'xihi') <_sre.SRE_Match object at 0x15693BF0> I guess you can consider re.match's pattern to be prefixed with '^'. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: [python-list] python application file format
Benjamin Jessup wrote: > Hello all, > > What do people recommend for a file format for a python desktop > application? Data is complex with 100s/1000s of class instances, which > reference each other. > > Write the file with struct module? (Rebuild object pointers, safe, > compact, portable, not expandable without reserved space) > > Use cPickle with a module/class whitelist? (Can't easily port, not > entirely safe, compact enough, expandable) > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > Any advice is greatly appreciated! I would think your options are pickle, json or database (either sqlite or something like Postgres). I am unfamiliar with the struct module so I cannot comment on its applicability. I would guess that your data would be best saved by using a sqlite database. Your biggest problem might be how the different classes are referencing each other. If you are using identifiers then any of these options will probably work. If you are using aggregation then I know that pickle will work (at least for built-in types). JSON will keep the structure but duplicate elements. >>> a = [ 1,2,3 ] >>> b = [ 'a', 'b', 'c' ] >>> a.append( b ) >>> e = [ a,b ] >>> s = json.dumps( e ) >>> eret = json.loads( s ) >>> id(eret[0][3]), id(eret[1]) # Same result for json and simplejson (329443808, 327677272) >>> eret[0][3].append( 'o') >>> eret[0][3], eret[1] ([u'a', u'b', u'c', 'o'], [u'a', u'b', u'c']) So pickle will be your easiest option, but I am not sure how well it will scale with a large number items. Using sqlite/db should scale well but it will take you longer/more effort to create a system for converting your objects to and from the DB. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Experimental Python-based shell
(A little quoting manipulation to make it easier to read with
appropriate context.)
> > On Wed, Oct 3, 2012 at 11:25 AM, Amirouche Boubekki
> > wrote:
> >
> 2012/10/3 Jonathan Hayward
> > > The chief benefit besides the searching, so far, is that you can use Py3k
> > > mixed with shell commands as the
> > > scripting language--so script in Python instead of bash.
> > >
> > > When using Python for scripting, Python lines are indented by an extra
> > > tab (or four spaces) while shell-like
> > > commands are not indented. So:
>
> > > cjsh> for index in range(10):
> > > > echo %(index)d
> > > >
> > > 0
> > > 1
> > > 2
[snip]
> >
> > > Echo could (and maybe should) be a built-in, but it isn't. The output is
> > > os.system()'ed to bash, which echoes
> > > based on a command that includes the value of a Python variable. The
> > > implementation is a bit crude, but it is
> > reasonably powerful.
> > >
> > > I have other things on the agenda, like making it able to run scripts and
> > > doing fuzzy matching, but for now
> > > those are the main two attractions.
> >
> > Is it possible to drop completly the bash syntax and use some python
> > library (I saw it on github) that wraps
> > bash commands with python functions or the other around making it possible
> > to call python functions with a bash-
> > like syntax. The syntax you are talking about seems strange.
> >
> > Regards,
> >
> > Amirouche
Jonathan Hayward wrote:
> I am open to suggestions and patches. I don't think the syntax strange,
> though: it offers a clear and distinct
> way to differentiate Python and shell commands, and shell commands can access
> Python variables when specified.
> And it is a simple rule, without footnotes needed.
I need more footnotes. :) Does every shell command not have indentation?
How can you tell if the shell command is supposed to be in the loop or after
the loop?
for index in range(10):
# do something
echo %(index)d
Is the above equivalent to Python pseudo-code solution A or B?
Solution A,
for index in range(10):
#do something
Popen('echo', file_path)
Solution B,
for index in range(10):
#do something
Popen('echo', file_path)
How do I make achieve the other solution?
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: final question: logging to stdout and updating files
Chris Angelico wrote: > Sent: Thursday, October 04, 2012 9:28 AM > To: [email protected] > Subject: Re: final question: logging to stdout and updating files > > On Fri, Oct 5, 2012 at 12:00 AM, Steven D'Aprano > wrote: > > That is *terrible* advice. But if you insist on following it, you can > > optimize *any* Python program to this: > > > > # === start code === > > pass # this line is optional > > # === end code === > > > > > > There you go. The most heavily optimized, fastest Python program in > > existence. Sure, it has a few bugs, but boy is it fast!!! > > Not many bugs though! I ran it in my Python 5.2.7 for GNU/Windows > 256-bit (err, yeah, I borrowed Guido's time machine but had the silly > thing in reverse... oops) and it worked perfectly, except that > indentation has moved from "significant" to "mandatory". When I added > the necessary 5 space indent at the beginning, it correctly created > world peace, ensured that Australia won the next Test Match, and then > printed "Hello, world!\n" to stdout. Unfortunately, a bug in your "end > code" comment meant that the peace it created was by wiping out all > life, but that's pretty minor in the scheme of things. Python is a product for Americans! ;) It should ensure America wins the Test Matchwait, do we even have a cricket team? > > Optimization really is that important, folks! > > ChrisA > may need to schedule surgical detongueing of his cheek Think we could get a group rate for c.l.p? Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: notmm is dead!
Steven D'Aprano wrote: > Sent: Thursday, October 04, 2012 7:22 PM > To: [email protected] > Subject: Re: notmm is dead! > > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > Dear list, > > > > Due to lack of energy and resources i'm really sad to announce the > > removal of notmm from pypi and bitbucket. > > Well that's just rude. Even if you don't intend to maintain the software > any more, why are you removing it from pypi? Since you say you are a fan > of Open Source software, just flag it as unmaintained and leave it for > somebody else to pick up. > > If you are going to abandon the project, release it on PyPI with a dual > MIT and GPL licence, and let it be taken over by somebody else. > > If you were looking for sympathy here, starting off by removing your > project from free hosting, then complaining that you can't pay for the > non-free hosting, was NOT the right way to do so. I might be misunderstanding, but I think Etienne wants money in exchange for letting someone else take over. > > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. > > This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Insert item before each element of a list
Agon Hajdari wrote: > Sent: Monday, October 08, 2012 3:12 PM > To: [email protected] > Subject: Re: Insert item before each element of a list > > On 10/08/2012 09:45 PM, Chris Kaynor wrote: > > [('insertme', i) for i in x] > > This is not enough, you have to merge it afterwards. Why do you say that? It seems to work just fine for me. >>> x [0, 1, 2, 3, 4] >>> [('insertme', i) for i in x] [('insertme', 0), ('insertme', 1), ('insertme', 2), ('insertme', 3), ('insertme', 4)] > > y = [item for tup in y for item in tup] > This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Insert item before each element of a list
Agon Hajdari wrote:
> On 10/08/2012 11:15 PM, Prasad, Ramit wrote:
> > Agon Hajdari wrote:
> >>
> >> On 10/08/2012 09:45 PM, Chris Kaynor wrote:
> >>> [('insertme', i) for i in x]
> >>
> >> This is not enough, you have to merge it afterwards.
> >
> > Why do you say that? It seems to work just fine for me.
> >
> >>>> x
> > [0, 1, 2, 3, 4]
> >>>> [('insertme', i) for i in x]
> > [('insertme', 0), ('insertme', 1), ('insertme', 2), ('insertme', 3),
> > ('insertme', 4)]
> >
> >>
> >> y = [item for tup in y for item in tup]
>
> I think he wanted to have a 'plain' list
> a = [0, 1, 0, 2, 0, 3]
> and not
> a = [(0, 1), (0, 2), (0, 3)]
You are absolutely correct. I missed that when I tried it.
Instead of the nested list comprehension, I might have used
map instead.
>>> y = [('insertme', i) for i in x]
>>> z = []
>>> _ = map( z.extend, y )
>>> z
['insertme', 0, 'insertme', 1, 'insertme', 2, 'insertme', 3, 'insertme', 4]
I am not sure which is more Pythonic, but to me map + list.extend tells
me more explicitly that I am dealing with an iterable of iterables.
It might make more sense to only to me though.
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Unpaking Tuple
Thomas Bach wrote: > Hi there, > > On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > > > my_tuple = my_tuple[:4] > > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > > > > Are you sure this works as you expect? I just stumbled over the following: > > $ python > Python 3.2.3 (default, Jun 25 2012, 23:10:56) > [GCC 4.7.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> split = ['foo', 'bar'] > >>> head, tail = split if len(split) == 2 else split[0], None > >>> head > ['foo', 'bar'] > >>> tail > >>> > > I don't get it! Could someone help me, please? Why is head not 'foo' > and tail not 'bar'? > > Regards, > Thomas > -- I think you just need to wrap the else in parenthesis so the else clause is treated as a tuple. Without the parenthesis I believe it is grouping the code like this. head, tail = (split if len(split) == 2 else split[0] ), None You want: head, tail = split if len(split) == 2 else (split[0], None ) Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: RE: Unpaking Tuple
Bob Martin wrote > in 682592 20121008 232126 "Prasad, Ramit" wrote: > >Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = > >03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= > >tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 else (my_= > >tuple + (None,)*4)[:4]=0D=0A> >=0D=0A> =0D=0A> Are you sure this works as y= > >ou expect? I just stumbled over the following:=0D=0A> =0D=0A> $ python=0D= > >=0A> Python 3=2E2=2E3 (default, Jun 25 2012, 23:10:56)=0D=0A> [GCC 4=2E7=2E= > >1] on linux2=0D=0A> Type "help", "copyright", "credits" or "license" for mo= > >re information=2E=0D=0A> >>> split =3D ['foo', 'bar']=0D=0A> >>> head, tail= > >=3D split if len(split) =3D=3D 2 else split[0], None=0D=0A> >>> head=0D=0A= > >> ['foo', 'bar']=0D=0A> >>> tail=0D=0A> >>>=0D=0A> =0D=0A> I don't get it! = > >Could someone help me, please? Why is head not 'foo'=0D=0A> and tail not 'b= > >ar'?=0D=0A> =0D=0A> Regards,=0D=0A> Thomas=0D=0A> --=0D=0A=0D=0AI think yo= > >u just need to wrap the else in parenthesis so the=0D=0Aelse clause is trea= > >ted as a tuple=2E Without the parenthesis =0D=0AI believe it is grouping th= > >e code like this=2E=0D=0A=0D=0Ahead, tail =3D (split if len(split) =3D=3D 2= > >else split[0] ), None=0D=0A=0D=0AYou want:=0D=0Ahead, tail =3D split if le= > >n(split) =3D=3D 2 else (split[0], None )=0D=0A=0D=0A=0D=0ARamit=0D=0AThis e= > >mail is confidential and subject to important disclaimers and=0D=0Aconditio= > >ns including on offers for the purchase or sale of=0D=0Asecurities, accurac= > >y and completeness of information, viruses,=0D=0Aconfidentiality, legal pri= > >vilege, and legal entity disclaimers,=0D=0Aavailable at http://www=2Ejpmorg= > >an=2Ecom/pages/disclosures/email=2E > > How does one unpack this post? ;-) > -- Hmm, I am not sure why that happened. For reference: http://mail.python.org/pipermail/python-list/2012-October/632603.html This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: for-loop on cmd-line
Chris Angelico wrote:
> On Fri, Oct 12, 2012 at 3:49 AM, Gisle Vanem wrote:
> > wrote in comp.lang.python
> >
> > (my ISP no longer updates this group. Last message is from 8. April.
> > Does the postings to the python mailing-list automatically get reposted to
> > comp.lang.python?)
>
> Yes, c.l.p and python-list mirror each other.
>
> >> C:\Windows\system32\python32.zip
> >> c:\python32\DLLs
> >
> >
> > I see a similar result:
> > f:\Windows\system32\python27.zip
> >
> > Where is it determined that python27.zip should be in sys.path?
> > I have no such file anywhere. I'm using ActivePython 2.7.2.
>
> It's in sys.path in the three Windows Pythons I have here:
>
> C:\Documents and Settings\M>python -c "import sys; print(sys.version);
> print('\n
> '.join(sys.path))"
> 2.4.5 (#1, Jul 22 2011, 02:01:04)
> [GCC 4.1.1]
>
> C:\Program Files\LilyPond\usr\lib\python24.zip
> C:\Program Files\LilyPond\usr\lib\python2.4
> C:\Program Files\LilyPond\usr\lib\python2.4\plat-mingw32
> C:\Program Files\LilyPond\usr\lib\python2.4\lib-tk
> C:\Program Files\LilyPond\usr\lib\python2.4\lib-dynload
> C:\Program Files\LilyPond\usr\lib\python2.4\site-packages
>
> C:\Documents and Settings\M>\python26\python -c "import sys;
> print(sys.version);
> print('\n'.join(sys.path))"
> 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
>
> C:\WINDOWS\system32\python26.zip
> C:\python26\DLLs
> C:\python26\lib
> C:\python26\lib\plat-win
> C:\python26\lib\lib-tk
> C:\python26
> C:\python26\lib\site-packages
>
> C:\Documents and Settings\M>\python32\python -c "import sys;
> print(sys.version);
> print('\n'.join(sys.path))"
> 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)]
>
> C:\WINDOWS\system32\python32.zip
> C:\python32\DLLs
> C:\python32\lib
> C:\python32
> C:\python32\lib\site-packages
> C:\python32\lib\site-packages\win32
> C:\python32\lib\site-packages\win32\lib
> C:\python32\lib\site-packages\Pythonwin
>
> C:\Documents and Settings\M>
>
> Presumably it's so that I can zip up my entire Python library and toss
> it into a convenient file. I don't think it costs much to stat a file
> and find it's not there before moving on, so it's not a problem to
> leave it there.
>
> ChrisA
Interesting, my results are slightly different. Here is what I
get from (one of) my Python installs.
2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]
C:\ramit\Python27\python27.zip
C:\ramit\Python27\DLLs
C:\ramit\Python27\lib
C:\ramit\Python27\lib\plat-win
C:\ramit\Python27\lib\lib-tk
C:\ramit\Python27
C:\ramit\Python27\lib\site-packages
Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Tkinter how to access the widget by name
? wrote:
> I'm a little teapot ... himself the question: if I want to appeal to the
> widget, knowing his name... ?
>
> # appropriated the name of the widget
> label = Label(frame, width = 40, text='text', name = 'name')
> ...
> name_='name'
> configure(name_)
> ...
> def configure(name_)
> #And how can that be?
> # At least let the text you want to change
>
> I beg you ..
> --
I am unfamiliar with Tkinter, so this might not be very helpful.
Usually with the GUI I have created before I uses classes and store
the widgets inside the classes. That makes it easier to use
`self.widgetname` or `getattr(self, widgetname)`. If that is not
something you can instead store the attributes in a list/dictionary.
In both cases make sure not to have multiple widgets created with
the same name.
Note the following is all untested and should be considered pseudo-code.
widgets = {}
label = Label(frame, width = 40, text='text', name = 'name')
widgets['name'] = label
def configure(name_):
widget = widgets[name_]
OR
widgets = []
label = Label(frame, width = 40, text='text', name = 'name')
widgets.append( label )
def configure(name_):
found = False
for w in widgets:
if w.name == name_: # No idea how to get name from Tk widget
found = True
break
if found:
# configure here
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Aggressive language on python-list
Steven D'Aprano wrote:
> On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:
>
> > The best advise is to ignore such posts and encourage others to do the
> > same.
>
> If you ignore such posts, how will the poster know they are unacceptable?
>
> How should somebody distinguish between "I am being shunned for acting
> like a dick", and "I have not received any responses because nobody has
> anything to add"?
>
> If I believe that your behaviour ("giving lousy advice") is causing great
> harm to this community, and *I don't say anything*, how will you know to
> change your behaviour? How will others know that I do not agree with your
> advice?
>
>
I agree completely. I was about to say that I was fine with meeting
known trolls with silence, but what happens when new or infrequent
readers see the troll's writing with no one objecting? Are they to
ignore the troll or assume that the list condones the troll's words?
~Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: system tray or notification area in python
Daniel Fetchinson wrote: > >> Hi folks, > >> > >> I'm using a stand alone window manager without gnome or kde or any > >> other de. But I still would like to have a system tray or notification > >> area and so far used stalonetray for this. Stalonetray is written in C > >> and is a GTK application, works all right but sometimes it doesn't. > >> For instance if it is killed and restarted icons don't come back, etc, > >> etc, there are some quirks. > >> > >> So I thought I would write a brand new stand alone system tray or > >> notification area in python. I guess I need to use gtk bindings or > >> some such but don't really know what my options are. > >> > >> Where would I start something like this? > >> Any pointers would be greatly appreciated! > >> > > Why not look at the source code of the current app your using to get > > an idea how that application accomplishes said task? > > I actually did that already it's using the C bindings of gtk. > You might ask you I'm not modifying the code in order to achieve what > I want, well, the answer is that I'd much rather prototype something > like this in python than work immediately with gtk from C. > > But I have zero experience with gui programming in python. So any > pointers would be much appreciated how to implement a system tray in > python. Gtk is I guess just one option, one could use other stuff from > python but I wouldn't know what the simplest approach is. > > I have used wxpython and thought it was powerful and reasonably easy to use. I have no experience with other Python frameworks but I know wxpython is a popular choice and I would guess it has an active community. That is my two cents (or lowest denomination currency for your locale). > > > You could always use raw X11 libs but leveraging something like Gtk or > > Qt/KDE would probably be much easier. > ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: OT Questions
David Hutto wrote: > On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht wrote: > > * Your strength is not design. Using bevel and emboss (and a pattern here > > and there) does not constitute good > design. > > It's simplicity within a symbolism, and now that I need money for > medical reasons, the work I've done isn't perfect, but it's on par. > > I know when I see something aesthetically pleasing, and if I like what > I have, I'm using the same mindset. > > If you're showcasing logo work, I hope you're ready to supply > variations that can be used cross-medium. > > These are all portfolio sites of my own, and I'm slowly revising them, > just like any other rough draft, and as you can tell I'm asking other > people to critique it. > Aesthetics and web design are relative to the eye of the beholder. The question is whose opinion matters. Yours? Mine? Others? Personally, I heartily second the recommendation to get professional advice on site design. Your site reminds me of something I would create in the '90s with FrontPage (do people even use that anymore?) as an amateur or hobbyist; not something I would create as a professional attempting to market my services. Now I do not say this in order to be mean, but to provide constructive criticism. Not because I do not like the site; but because I think *other* people will not like the site layout and ultimately my opinion does not matter; it matters what your prospective clients think. That is unless you can afford to turn away business by sticking to your design principles. Several top level links did not work and that is a bad sign for a portfolio. At the very least, take a few minutes to setup a blank page so the visitor does not get a 404 error. The background of your logo page should match the color scheme of the rest of the website. Oh, and your logo for your main page is incomprehensible to me. I am not sure if it is a artistic design or some text, but it is too hard to make out. It is hard to say much more since the site is so bare. I will reiterate what others have said regarding background sounds (especially ones that start by default). If you take a look at some famous websites and you will notice that they rarely have sound and for good reason. Another thing to note is wasted space. Network bandwidth is a commodity. You pay for it and your visitor pays for it. You pay for it in terms of hosting or internet service while the visitor pays for it in internet service and possibly even in their data cap. I cannot imagine loading your website from a phone (nor would I ever try to). You want to be as efficient as possible. Have you ever taken a look at Google's home page source? Now they are an extreme example of keeping a site lean, but maybe that will give you an idea of how important it is. An overly giant GIF and sound files are poor choices. It should be easy to compress the GIF to a *much* smaller file size while keeping the animation. You can probably use a midi file for the same effect with regards to sounds. I hope that helps, Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: A desperate lunge for on-topic-ness
Den wrote: > On Wednesday, October 17, 2012 11:06:43 PM UTC-7, Zero Piraeus wrote: > > : > > > > > > What are people's preferred strategies for dealing with lines that go > > > > over 79 characters? A few I can think of off the bat: > > > > I personally just keep typing until my statement is finished. This is my > program, not PEP's. > > But I have to say I'm amused by the whole question, and others related to > PEP8. A quick aside, the width of our > roads all go back to the width of a two horse rig. The suggested maximum of > 80 characters goes back to teletype > machines, and IBM cards, and character based terminals > > Should that really be the basis for a suggested style now? > > Den Unlike IBM cards and the teletype, character based terminals are still widely used (at least in the developer communities). They often default to 80 characters, but handle various sizes. So that comparison is not quite fair. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: A desperate lunge for on-topic-ness
Chris Angelico wrote: > On Fri, Oct 19, 2012 at 3:13 AM, Neil Cerutti wrote: > > Though technology has moved along swiftly, keeping your code > > accessible to the guy using a crummy old console xterm might > > still be worthwhile, and it makes printouts easy to create. > > And keeping your interface accessible to someone who can't use the > Home and End keys allows it to be used by someone who's using PuTTY on > Windows to SSH to a gateway and then SSH from there to a firewalled > computer that's running your application. And yes, I do exactly that, > and yes, for some reason Home/End don't always work. One day I'll > probably figure out what the issue is, but for now, I'm just glad > there are baseline text editors that don't need such keys... > > Technology moves on, but not everywhere. > > ChrisA > -- Home and end do not bother me much as I can usually use ctrl+a/ctrl+e for the same purpose. I do wish I found a better way to page up/down. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: OT Questions
David Hutto wrote: > On Wed, Oct 17, 2012 at 7:12 PM, Steven D'Aprano > wrote: > > On Wed, 17 Oct 2012 18:05:12 -0400, Dwight Hutto wrote: > > > >> this was just a confidence statement that I'm > >> intelligent as well, so don't get uppity with me. > > > > Please tone down the aggression. > > > > > It's email, things get misinterpreted sometimes. > True, which is why we should all take a little extra care in what we write to avoid misinterpretation, especially in terms of offensiveness. Besides, what you write here is public and can be seen by anyone with access to the Internet and a search engine. That includes prospective clients/employers! I know there is an increasing trend for employers to search the Internet to learn about potential employees. I do the same before I hire a company for many things (e.g. house/car repair, translator, etc). Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: OT Questions
David Hutto wrote: > On Wed, Oct 17, 2012 at 12:38 PM, Prasad, Ramit > wrote: > > David Hutto wrote: > >> On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht > >> wrote: [snip] > > > The question is whose opinion matters. Yours? Mine? Others? Personally, > > I heartily second the recommendation to get professional advice on site > > design. Your site reminds me of something I would create in the '90s > > with FrontPage (do people even use that anymore?) as an amateur or > > hobbyist; not something I would create as a professional attempting > > to market my services. > > > I'm moving toward the smaller devices, but I'm a desktop guy, and so > are a lot of others. And what site doesn't have a frontpage? Just to clarify Microsoft FrontPage was a late 90s/early-2000's application for creating web pages with a WYSIWYG front end. The precursor to Adobe's Dreamweaver and sort of the web design equivalent of Microsoft Word. [snip] Out of curiosity, is there a reason you did not pick Python (seeing as this is a Python mailing list) for this task? Or conversely, is there a reason you picked PHP? Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: A desperate lunge for on-topic-ness
Hans Mulder wrote:
> On 18/10/12 08:31:51, Steven D'Aprano wrote:
> > On Thu, 18 Oct 2012 02:06:19 -0400, Zero Piraeus wrote:
> >> 3. Say "well, at least it's not a backslash" and break the line using
> >> > parentheses.
> > I mostly do this. Since most lines include a bracket of some sort, I
> > rarely need to add outer parentheses just for the purpose of line
> > continuation.
> >
> > some_variable = spam('x') + ham(
> > some_longer_variables, here_and_here,
> > and_here_also)
>
> I would spell that as:
>
> some_variable = spam('x') + ham(
> some_longer_variables,
> here_and_here,
> and_here_also,
> )
>
> > I know PEP 8 says I should drop the final round bracket to the next line,
> > but I don't normally like that.
>
> I normally put the final bracket on the next line, where it is
> very visible. Compare:
>
> if looks_like_it_might_be_spam(
> some_longer_variables,
> here_and_here, and_here_also):
> logger.notice("might be spam")
> move_to_spam_folder(some_longer_variables)
> update_spam_statistics(here_and_here)
>
> vs.
>
> if looks_like_it_might_be_spam(
> some_longer_variables,
> here_and_here,
> and_here_also,
> ):
> logger.notice("might be spam")
> move_to_spam_folder(some_longer_variables)
> update_spam_statistics(here_and_here)
>
> Which one would you say is more readable?
>
For the first example, I would probably indent the arguments more
to differentiate a continuing line. That way the "):" does not
look like it was un-indented to be part of a different block.
if looks_like_it_might_be_spam(
some_longer_variables,
here_and_here, and_here_also):
logger.notice("might be spam")
move_to_spam_folder(some_longer_variables)
update_spam_statistics(here_and_here)
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: len() on mutables vs. immutables
Terry Reedy wrote: > On 10/18/2012 1:23 PM, Demian Brecht wrote: > > > When len() is called passing an immutable built-in type (such as a > > string), I'd assume that the overhead in doing so is simply a function > > call and there are no on-call calculations done. Is that correct? > > See below. > > > I'd also assume that mutable built-in types (such as a bytearray) would > > cache their size internally as a side effect of mutation operations. Is > > Or the length could be the difference of two pointers -- address of the > first empty slot minus address of first item. > > > that correct? If so, is it safe to assume that at least all built-in > > types observe this behavior, > > str, bytes, bytearrays, arrays, sets, frozensets, dicts, dictviews, and > ranges should all return len in O(1) time. That includes the possibility > of a subtraction as indicated above. > Why does pointer arithmetic work for dicts? I would think the position of a value would be based on the hash of the key and thus "random" for the context of this conversation. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: len() on mutables vs. immutables
Ian Kelly wrote: > Sent: Thursday, October 18, 2012 2:39 PM > To: Python > Subject: Re: len() on mutables vs. immutables > > On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit > wrote: > > Why does pointer arithmetic work for dicts? I would think the position > > of a value would be based on the hash of the key and thus "random" for > > the context of this conversation. > > It doesn't. len() on CPython dicts is O(1) because the dict keeps > track of how many items it contains. It needs to do this anyway so > that it can determine when to grow the internal hash table. That is what I was thinking "should" happen. Thanks for the clarification Ian. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: pip fails to install packages on moutain loin (Mac OS 10.8.2)
Peng Yu wrote > 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 the following error message. > > Does anybody have a solution to install python on Mac OS 10.8.2 so > that packages can be installed with pip? > > /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/exception: > 42:28: error: bits/c++config.h: No such file or directory > In file included from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c+ > +/4.2.1/bits/stl_algobase.h:70, > from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c+ > +/4.2.1/bits/char_traits.h:46, > from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c+ > +/4.2.1/string:47, > from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c+ > +/4.2.1/stdexcept:44, > > Regards, > Peng I would install python+virtualenv+pip from MacPorts to keep it separate from the OS X system Python. MacPorts will take care of everything for you as long as you have Xcode installed. `sudo ports install py27-pip` Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Python does not take up available physical memory
Emile van Sebille wrote: > On 10/19/2012 10:08 AM, Pradipto Banerjee wrote: > > Hi, > > > > I am trying to read a file into memory. The size of the file is around 1 > > GB. I have a 3GB memory PC and the Windows Task Manager shows 2.3 GB > > available physical memory when I was trying to read the file. I tried to > > read the file as follows: > > > fdata = open(filename, 'r').read() > > > > I got a "MemoryError". I was watching the Windows Task Manager while I > > run the python command, and it appears that python **perhaps** never > > even attempted to use more memory but gave me this error. > > > > Is there any reason why python can't read a 1GB file in memory even when > > a 2.3 GB physical memory is available? > > The real issue is likely that there is more than one copy of the file in > memory somewhere. I had a similar issue years back that I resolved by > using numeric (now numpy?) as it had a more efficient method of > importing content from disk. > > Also realize that windows may not allow the full memory to user space. > I'm not sure what exactly the restrictions are, but a 4Gb windows box > doesn't always get you 4Gb of memory. > Windows (by default) limits user space of a 32 bit machine to 2 GB. This is a bit old but I think still applies to pre-Win7. (scroll down to "32-bit Client Effective Memory Limits" ) http://blogs.technet.com/b/markrussinovich/archive/2008/07/21/3092070.aspx Offhand, I am not sure how this works in Win7, but for 32-bit clients I doubt it has changed much. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Python does not take up available physical memory
Chris Angelico wrote: > On Sat, Oct 20, 2012 at 4:08 AM, Pradipto Banerjee > wrote: > > I am trying to read a file into memory. The size of the file is around 1 GB. > > I have a 3GB memory PC and the Windows Task Manager shows 2.3 GB available > > physical memory when I was trying to read the file. I tried to read the file > > as follows: > > > > > > > >>>> fdata = open(filename, 'r').read() > > Is this Python 2 or Python 3? Just throwing a random possibility out > there, could it be that reading it in and converting it to Unicode > text requires more memory than you have? > > My recommendation: Unless you actually need to search the whole file > as a single string, iterate over the file instead: > > for line in open(filename): > # do something with line If you (OP) are in Python 2.5+ I would do the following instead. with open(filename) as f: for line in f: # do something with line This will automatically close the file when it is done. I doubt it will help with memory issues, but closing files after you are done with them is a Good practice. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Python does not take up available physical memory
Pradipto Banerjee wrote: > Thanks, I tried that. Still got MemoryError, but at least this time python > tried to use the physical memory. > What I noticed is that before it gave me the error it used up to 1.5GB (of > the 2.23 GB originally showed as > available) - so in general, python takes up more memory than the size of the > file itself. Of course it will. Python has to keep its own code in memory and load the file. Not to mention that the file is converted from data into a Python object with its own overhead. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Is there a way to programmatically turn on remote registry?
Kevin Holleran wrote: > Hi, > > I have written a script to poll some registry values but remote registry is > turned off through GPO on the > network I need to run it against. The account running the script is an admin > on these boxes. Is there a way > for me to turn on remote registry for the duration of the script's runtime? > > Thanks for your help. > > Kevin No personal experience but the web says you need to enable the remote registry service[1]. You can start and stop services in Python using win32serviceutil[2]. [1] http://technet.microsoft.com/en-us/library/cc754820.aspx [2] http://fuzzytolerance.info/using-python-to-manage-windows-services/ Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Tkinter Create/Destory Button
[email protected] wrote: > I am trying to create a button in Tkinter and then when it is pressed delete > it/have it disappear. Does anyone > know the simplest script to do that with. Thanks for your help. Try http://www.gossamer-threads.com/lists/python/python/118851 . If you just want to disable/enable the button while leaving it visible maybe try setting the config state as shown here: http://www.daniweb.com/software-development/python/threads/69669/tkinter-button-disable-# . Hope that helps, Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: A desperate lunge for on-topic-ness
Roy Smith wrote: > Pet peeve of the day... > > Why do you have to write: > > global foo > foo = 4 > > when > > global foo = 4 > > would have been so much easier? To make it more annoying for people who use globals, duh. :) Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: regex function driving me nuts
MartinD wrote:
> Hi,
>
> I'm new to Python.
> Does someone has an idea what's wrong. I tried everything. The only regex
> that is tested is the last one in a
> whole list of regex in keywords.txt
> Thanks!
> Martin
>
>
>
> def checkKeywords( str, lstKeywords ):
>
> for regex in lstKeywords:
> match = re.search(regex, str,re.IGNORECASE)
> # If-statement after search() tests if it succeeded
> if match:
> print match.group() ##just debugging
> return match.group() ## 'found!
>
> return
>
> #
>
> keywords1 = [line for line in open('keywords1.txt')]
> resultKeywords1 = checkKeywords("string_to_test",keywords1)
> print resultKeywords1
>
Hi Martin,
It is always helpful to provide python version, operating system version, full
error message,
and input/expected output for the code. Now I can tell you are using Python 2.x
but
without having any clue what is in keywords1.txt it is impossible to figure out
what the problem might be. Other than using regular expressions that is. :)
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: SQLAlchemy: How to do Table Reflection and MySQL?
Nick Sabalausky wrote: > On Mon, 22 Oct 2012 14:35:23 -0700 (PDT) > darnold wrote: > > > > i'm not brave enough to dig too deeply into SQLAlchemy, but maybe this > > will help? : > > > > http://kashififtikhar.blogspot.com/2010/07/using-sqlalchemy-reflection-with-pylons.html > > > > that came up from googling "sqlalchemy table reflection tutorial". > > Thanks, your view of Google seems to be far better tailored for Python > than mine is, that doesn't come up for me anywhere on the first five > pages of results for that query. > > Unfortunately the info on that page doesn't seem to work for me: > > -- > from sqlalchemy import * > from sqlalchemy.orm import sessionmaker > > engine = create_engine(my connection string) > meta = MetaData() > meta.bind = engine > meta.reflect() > > Session = sessionmaker(bind=engine) > session = Session() > > res = session.query(user).filter(user.name=="bert").first() > print res.name > -- > > That just gives me: > > NameError: name 'user' is not defined > > (And yes, the code given on that page to print out the table info > *does* indicate a table named 'user' was found.) This does not seem to be a SQLAlchemy problem. Instead it seems there is not a variable called `name`. If you define the appropriate user it does it work? (From that page it seems like user should be a blank class like the following). class user(object): pass > > I also tried this which also fails: > > res = > session.query(meta.tables["user"]).filter(meta.tables["user"].name=="bert").first() > > sqlalchemy.exc.ArgumentError: filter() argument must be of type > sqlalchemy.sql.ClauseElement or string > > The page you linked to appears to get around the matter by manually > setting up tables filled with the reflected info, but that seems to > defeat much of the point for me. I may as well just set up the tables > manually without the reflection, which is what I'll probably do. > > Maybe I just misunderstood what was meant in the SQLAlchemy docs here?: > > "but note that SA can also “import” whole sets of Table objects > automatically from an existing database (this process is called table > reflection)." -- > http://docs.sqlalchemy.org/en/rel_0_7/core/tutorial.html > > It said that but then didn't say how and didn't link to any info on how. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Appending a list using list obtained from a class
Demian Brecht wrote: > On 2012-10-24, at 8:00 AM, inshu chauhan wrote: > > > Yes, a Class method returns a list. I am trying to append this in main() to > > make another list. > > But the list i am getting after appending i showing addresses like this > > '<__main__.Point object at > 0x0254FAB0>' but if i print the same in the same loop its showing me numbers > which i want. Why I dont know ?? > > If you can, please post the relevant blocks of code. That'll be a tremendous > help in figuring out your problem. > I would like to re-iterate that posting the relevant code is very helpful and the best way for us to help you. Everything below is an educated guess based on the information you provided. Based on the text '<__main__.Point object at 0x0254FAB0>', it seems like the object being returned is most likely NOT a list but instead a Point class that is iterable. Either that or it is a list of Point objects. To find out exactly, try something like this: lst = # whatever your class is returning. print 'LIST - type : ', type(lst) '\trepr: ', repr(lst), '\tstr :', str(lst) for p in lst[-1:]: print 'POINT - type: ', type(p) '\trepr: ', repr(p), '\tstr :', str(p) My suspicion is that when you print the list containing points/addresses it prints the repr version. When you print the points/addresses themselves it prints the str version. >>> class t(object): ... def __str__(self): ... return 'str' ... def __repr__(self): ... return 'repr' ... >>> a = t() >>> print [a] [repr] >>> print a str >>> print a.__class__.__base__.__repr__(a) <__pieshell__.t object at 0x11B28F10> Hope that helps you to understand what is going on. Ramit Prasad P.S. Usually it is best to specify, Python version, OS version, expected input/output, and the smallest code sample you can provide that shows the problem (that any reader of your message can run). This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: resume execution after catching with an excepthook?
andrea crotti wrote: > 2012/10/25 Steven D'Aprano : > > On Wed, 24 Oct 2012 13:51:30 +0100, andrea crotti wrote: > > [snip] > > Without a try...except block, execution will cease after an exception is > > caught, even when using sys.excepthook. I don't believe that there is any > > way to jump back to the line of code that just failed (and why would you, > > it will just fail again) or the next line (which will likely fail because > > the previous line failed). > > > > I think the only way you can do this is to write your own execution loop: > > > > while True: > > try: > > run(next_command()) > > except KeyboardInterrupt: > > if confirm_quit(): > > break > > > > > > Of course you need to make run() atomic, or use transactions that can be > > reverted or backed out of. How plausible this is depends on what you are > > trying to do -- Python's Ctrl-C is not really designed to be ignored. > > > > Perhaps a better approach would be to treat Ctrl-C as an unconditional > > exit, and periodically poll the keyboard for another key press to use as > > a conditional exit. Here's a snippet of platform-specific code to get a > > key press: > > > > http://code.activestate.com/recipes/577977 > > > > Note however that it blocks if there is no key press waiting. > > > > I suspect that you may need a proper event loop, as provided by GUI > > frameworks, or curses. > > > > Ok thanks, but here the point is not to resume something that is going > to fail again, just to avoid accidental kill of processes that take a > long time. Probably needed only by me in debugging mode, but anyway I > can do the simple try/except then, thanks.. On the other hand, if you store state externally (pickle?) maybe you can just restart at the last "check point". That way even if the program dies you can recover on the next run. Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: turn list of letters into an array of integers
David Hutto wrote:
> On Wed, Oct 24, 2012 at 1:23 AM, seektime wrote:
> > Here's some example code. The input is a list which is a "matrix" of
> > letters:
> >a b a
> >b b a
> >
> > and I'd like to turn this into a Python array:
> >
> > 1 2 1
> > 2 2 1
> >
> > so 1 replaces a, and 2 replaces b. Here's the code I have so far:
> >
> >>>> L=['a b a\n','b b a\n']
> >>>> s=' '.join(L)
> >>>> seq1=('a','b')
> >>>> seq2=('1','2')
> >>>> d = dict(zip(seq1,seq2))
> >>>> # Define method to replace letters according to dictionary (got this from
> http://gommeitputor.wordpress.com/2008/09/27/search-replace-multiple-words-or-characters-with-python/).
> > ... def replace_all(text, dic):
> > ... for i, j in dic.iteritems():
> > ... text = text.replace(i, j)
> > ... return text
> > ...
> >
> >>>> seq = replace_all(s,d)
> >>>> print seq
> > 1 2 1
> > 2 2 1
> >
> >>>> seq
> > '1 2 1\n 2 2 1\n'
> >
> I'd suggest, if this is what you're referring to:
>
> x = seq.split('\n ')
> array_list = [ ]
> next_3_d_array = []
> range_of_seq = len(seq)
> for num in range(0,range_of_seq):
>if num % 3 != 0:
>next_3_d_array.append(num)
>if num % 3 == 0:
>array_list.append(next_3_d_array)
>next_3_d_array = [ ]
>
Wow, that looks complicated. Why hardcode to 3 instead of where ever
the newline is?
>>> [ int(x.strip()) for subseq in seq.split('\n') for x in subseq.split() ]
[1, 2, 1, 2, 2, 1]
>>> lst = []
# OR
>>> for subseq in seq.split('\n'):
... for x in subseq.split():
... lst.append( int(x.strip()))
...
>>>
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: better way for ' '.join(args) + '\n'?
Thomas Rachel wrote:
> Am 26.10.2012 09:49 schrieb Ulrich Eckhardt:
> > Hi!
> >
> > General advise when assembling strings is to not concatenate them
> > repeatedly but instead use string's join() function, because it avoids
> > repeated reallocations and is at least as expressive as any alternative.
> >
> > What I have now is a case where I'm assembling lines of text for driving
> > a program with a commandline interface.
>
> Stop.
>
> In this case, you think too complicated.
>
> Just do
>
> subprocess.Popen(['prog', 'foo', 'bar', 'baz'])
>
> - is the most safest thing for this use case.
>
> If it should not be possible for any reason, you should be aware of any
> traps you could catch - e.g., if you want to feed your string to a
> Bourne shell, you should escape the strings properly.
>
> In such cases, I use
>
>
> def shellquote(*strs):
> r"""Input: file names, output: ''-enclosed strings where every ' is
> replaced with '\''. Intended for usage with the shell."""
> # just take over everything except ';
> # replace ' with '\''
> # The shell sees ''' as ''\'''\'''\'''. Ugly, but works.
> return " ".join([
> "'"+st.replace("'","'\\''")+"'"
> for st in strs
> ])
>
>
> so I can use
>
> shellquote('program name', 'argu"ment 1', '$arg 2',
> "even args containing a ' are ok")
>
> For Windows, you'll have to modify this somehow.
>
The subprocess module suggests using pipes.quote for escaping.
>>> a
('program name', 'argu"ment 1', '$arg 2', "even args containing a ' are ok")
>>> import pipes
>>> map(pipes.quote, a)
["'program name'", '\'argu"ment 1\'', "'$arg 2'", '\'even args containing a
\'"\'"\' are ok\'']
>>> ' '.join(a)
'\'program name\' \'argu"ment 1\' \'$arg 2\' \'even args containing a \'\\\'\'
are ok\''
Ramit Prasad
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: how to change os.popen4 to subprocess
Replying to skyworld because I could not find the original message from MRAB. skyworld wrote: > On Oct 27, 11:02 am, MRAB wrote: > > On 2012-10-27 03:28, skyworld wrote:> Hi, > > > > > I'm new to python and I'm trying to porting some scripts from v0.96 to > > > v2.0.1. A piece of code is like this: > > > > > cmd_h = os.popen4(env['SYSCMDLINE'])[1] > > > > > the system indicates the popen4 is deprecated and suggest to use > > > subprocess. Can anybody tell me how to use subprocess in this case? > > > and what does "[1]" here means? > > > > os.popen4 returns a tuple of (child_stdin, child_stdout_and_stderr). > > The [1] gets the child_stdout_and_stderr member. > > > > Using the subprocess module: > > > > # Untested! > > cmd_h = subprocess.Popen(env['SYSCMDLINE'], stdout=subprocess.PIPE, > > stderr=subprocess.STDOUT, shell=True).stdout > > > > Explanation: > > > > The command line: env['SYSCMDLINE'] > > > > Return stdout: stdout=subprocess.PIPE > > > > stderr should be combined with stdout: stderr=subprocess.STDOUT > > > > Let the shell parse the command line: shell=True > > thanks > -- I thought the usage of shell=True is usually discouraged? The subprocess documentation[0] should be helpful to figure it out. """ Warning: Invoking the system shell with shell=True can be a security hazard if combined with untrusted input. See the warning under Frequently Used Arguments for details. """ [0] http://docs.python.org/2/library/subprocess.html Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: date and time comparison how to
Gary Herron wrote: > On 10/29/2012 04:13 PM, noydb wrote: > > All, > > > > I need help with a date and time comparison. > > > > Say a user enters a date-n-time and a file on disk. I want to compare the > > date and time of the file to the > entered date-n-time; if the file is newer than the entered date-n-time, add > the file to a list to process. > > > > How best to do? I have looked at the datetime module, tried a few things, > > no luck. > > > > Is os.stat a part of it? Tried, not sure of the output, the > > st_mtime/st_ctime doesnt jive with the file's > correct date and time. ?? > > > > Any help would be appreciated! > > Use the datetime module (distributed with Python) to compare date/times. > > You can turn a filesystem time into a datetime with something like the > following: > import datetime, os, stat > mtime = os.lstat(filename)[stat.ST_MTIME] // the > files modification time > dt = datetime.datetime.fromtimestamp(mtime) > You could also write that as: datetime.datetime.fromtimestamp( os.path.getmtime( path ) ) Ramit P This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Obnoxious postings from Google Groups
Grant Edwards wrote: > On 2012-11-05, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> It's nothing to do with operating system. File names are names, and > >> spaces in them are seldom worth the hassle unless you manipulate those > >> files solely using a GUI. > > > > That's a very ascii-esqe attitude. In a fully unicode world, I could > > easily see using U+00A0 (NO-BREAK SPACE) in file names, and still have > > space-delimited CLI work just fine. > > No, it wouldn't work just fine. You'd never know when looking at > names whether it was a "regular" space or a "no-break space", and > names would be visually ambiguous. Visually ambiguous names are > horrible. Not to mention that in the GUI I (usually) want the space to be a "break space". > > > But, yeah, in the world we live in today, I try to avoid spaces in > > filenames. But, instead of turning "My File Name" into MyFileName, I'll > > usually do it as My-File-Name or My_File_Name. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Obnoxious postings from Google Groups
Steven D'Aprano wrote: > > On Mon, 05 Nov 2012 14:47:47 -0500, Dennis Lee Bieber wrote: > [snip] > > Nevertheless, I do tend to prefer underscores to spaces, simply because I > often use naive tools that treat spaces as separators. That is, command > line shells. I visually prefer spaces but it is easier to work with underscores. Thankfully there are plenty of command line utilities for pattern renaming that let me shift to and from spaces as necessary. > > For what it's worth, you can enter any control character in Unix/Linux > systems with readline in bash using the C-q key combination. Newline > needs a bit of special treatment: you need to wrap the name in single > quotes to stop the newline from being interpreted as the end of the > command. > > [steve@ando temp]$ touch 'foo > bar' > > To enter the newline, I typed Ctrl-Q to tell bash to treat the next > character as a literal, and then typed Ctrl-J to get a newline. That sounds complicated, my version of bash lets me type 'foobar' for the same effect. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Multi-dimensional list initialization
Ian Kelly wrote: > > On Tue, Nov 6, 2012 at 1:21 AM, Andrew Robinson > [snip] > > See if you can find *any* python program where people desired the > > multiplication to have the die effect that changing an object in one of the > > sub lists -- changes all the objects in the other sub lists. > > > > I'm sure you're not going to find it -- and even if you do, it's going to be > > 1 program in 1000's. > > Per the last thread where we discussed extremely rare scenarios, > shouldn't you be rounding "1 in 1000s" up to 20%? ;-) Actually, I would be surprised if it was even 1 in 1000. Of course, consistency makes it easier to learn and *remember*. I value that far more than a minor quirk that is unlikely to bother me now that I know of it. Well, at least not as long as I do not forget my morning coffee/tea :) ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Logging output to be redirected to a particular folder
Dennis Lee Bieber wrote: > > On Tue, 06 Nov 2012 13:26:11 +0100, Peter Otten <[email protected]> > declaimed the following in gmane.comp.python.general: > > > [email protected] wrote: [snip] > > > def main(): > > >logging.basicConfig(Filename='c://myapp.log', level=logging.ERROR) > > > > Python is case-sensitive. Try: > > > > logging.basicConfig(filename='c://myapp.log', level=logging.ERROR) > > > The double forward slashes might also be confusing... At the least, > unneeded... > > >>> import os.path > >>> print os.path.normpath("c://somefile.log") > c:\somefile.log > >>> print os.path.normpath("c:\\somefile.log") > c:\somefile.log > >>> print os.path.normpath("c:\\tryfile.log") > c:\tryfile.log > >>> print os.path.normpath("c:\tryfile.log") > c:ryfile.log > >>> print os.path.normpath("c:/tryfile.log") > c:\tryfile.log > >>> > > Doubling back-slashes is needed to avoid the problem of literal > escapes corrupting the intent... Or use the raw literal form r"c:\tryfile.log". I know several people that prefer to use forward slashes as it works in both Windows and *nix. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: who can give me some practical tutorials on django 1.4 or 1.5?
Levi Nie wrote: > > Who can give me some practical tutorials on django 1.4 or 1.5? > Thank you. Maybe this will help: http://gettingstartedwithdjango.com/resources/ ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Obnoxious postings from Google Groups
Steven D'Aprano wrote: > > On Tue, 06 Nov 2012 17:16:44 +0000, Prasad, Ramit wrote: > > >> To enter the newline, I typed Ctrl-Q to tell bash to treat the next > >> character as a literal, and then typed Ctrl-J to get a newline. > > > > That sounds complicated, my version of bash lets me type > > 'foobar' for the same effect. > > Well, I learned something new about bash. > > On the other hand, the Ctrl-Q next-char-is-literal trick works for > entering control characters that otherwise don't have a key on the > keyboard. > Would you mind elaborating on how this works? I know it's not a bash list, but I do not understand how ctrl-J is considered a literal. Obviously, I must have a different definition of "literal". Where can I find a list of other literals? My Google-fu is being weak today. :( ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Multi-dimensional list initialization
Andrew Robinson wrote:
>
> On 11/06/2012 01:04 AM, Steven D'Aprano wrote:
> > On Mon, 05 Nov 2012 21:51:24 -0800, Andrew Robinson wrote:
> >
[snip]
> > Q: What about other mutable objects like sets or dicts?
> > A: No, the elements are never copied.
> They aren't list multiplication compatible in any event! It's a total
> nonsense objection.
>
> If these are inconsistent in my idea -- OBVIOUSLY -- they are
> inconsistent in Python's present implementation. You can't even
> reference duplicate them NOW.
>
> >>> { 1:'a', 2:'b', 3:'c' } * 2
> Traceback (most recent call last):
>File "", line 1, in
> TypeError: unsupported operand type(s) for *: 'dict' and 'int'
>>> z = [ {'a':1} ]*10
>>> z[0]['b'] = 4
>>> z
[{'a': 1, 'b': 4}, {'a': 1, 'b': 4}, {'a': 1, 'b': 4},{'a': 1, 'b': 4},
{'a': 1, 'b': 4}, {'a': 1, 'b': 4}, {'a': 1, 'b': 4}, {'a': 1, 'b': 4},
{'a': 1, 'b': 4}, {'a': 1, 'b': 4}]
Should that copy the dictionary? According to logical reasoning
it should copy the dictionary as well. How do you draw the line of
what should be copied and what should not?
>
> > Q: How about on Tuesdays? I bet they're copied on Tuesdays.
> > A: No, the elements are never copied.
> That's really a stupid objection, and everyone knows it.
Agreed. [snip]
> > Q: How about if I use delegation to proxy a list?
> > A: Oh no, they definitely won't be copied.
> Give an example usage of why someone would want to do this. Then we can
> discuss it.
IIRC, someone wanted to do something very similar for dictionaries to
prevent editing of global variables.
> > Q: What about other mutable objects like sets or dicts?
> > A: No, definitely not. Unless people complain enough.
> now you're just repeating yourself to make your contrived list longer --
> but there's no new objections...
This is my main objection and one of the flaws of your argument.
You want to handle one type of mutable objects completely separately
than other mutable objects. Why is list any different than dictionary
in this respect? The only reason I can imagine is because lists
end up being used for 2d (or higher) "matrices".
>
> > Losing consistency in favour of saving a few characters for something as
> > uncommon as list multiplication is a poor tradeoff. That's why this
> > proposal has been rejected again and again and again every time it has
> > been suggested.
> Please link to the objection being proposed to the developers, and their
> reasoning for rejecting it.
> I think you are exaggerating.
I reject (as a developer) it because it forces me to remember a very
specific quirk versus a simple (logical) rule that applies to all objects. Not
to mention that the quirk is not even that useful except for beginners.
>
> > List multiplication [x]*n is conceptually equivalent to:
> >
> > This is nice and simple and efficient.
> No it isn't efficient. It's *slow* when done as in your example.
>
> > Copying other objects is slow and inefficient. Keeping list
> > multiplication consistent, and fast, is MUCH more important than making
> > it work as expected for the rare case of 2D arrays:
> I don't think so -- again, look at range(); it was made to work
> inconsistent for a "common" case.
>
> Besides, 2D arrays are *not* rare and people *have* to copy internals of
> them very often.
> The copy speed will be the same or *faster*, and the typing less -- and
> the psychological mistakes *less*, the elegance more.
>
> It's hardly going to confuse anyone to say that lists are copied with
> list multiplication, but the elements are not.
>
> Every time someone passes a list to a function, they *know* that the
> list is passed by value -- and the elements are passed by reference.
> People in Python are USED to lists being "the" way to weird behavior
> that other languages don't do.
I think you just lost 90% of your credibility (with me). When did lists
get passed by value? Python uses call by sharing[0].
Terminology aside, lists are handled exactly the same way as all
other objects; the rules regarding their mutability in the callee
are the same as dictionaries, sets, or any mutable type (including
non-builtins).
>
> >
> > Copying those elements does not come for free.
> >
> > It is true that list multiplication can be much faster than a list comp.
> > But that's because the list multiply doesn't have to inspect the
> > elements, copy them, or engage the iteration machinery. Avoiding copying
> > gives you a big saving:
> >
> >
> > [steve@ando ~]$ python3.3 -m timeit -s "x = range(1000)"
> > "[x for _ in range(100)]" # not copied
> > 10 loops, best of 3: 11.9 usec per loop
> >
> > [steve@ando utilities]$ python3.3 -m timeit -s "x = range(1000)"
> > "[x[:] for _ in range(100)]" # copied
> > 1 loops, best of 3: 103 usec per loop
> >
> > So there's a factor of ten difference right there. If list multiplication
> > had to make copies, it would lose much of its speed advantage.
> And when multiplicati
RE: How to only get a list of the names of the non-directory files in current directory ('.')?
iMath wrote: > how to get a list of names of everything in the current directory ? http://lmgtfy.com/?q=python+get+files+in+directory ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Multi-dimensional list initialization
Gregory Ewing wrote: > > Roy Smith wrote: > > Call by social network? The called function likes the object. > > Depending on how it feels, it can also comment on some of the object's > > attributes. > > And then finds that it has inadvertently shared all its > private data with other functions accessing the object. And this is where Dihedral (or whatever the bot is called) tells you that Python has no "private" variables. :) ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Right solution to unicode error?
Anders wrote: > > I've run into a Unicode error, and despite doing some googling, I > can't figure out the right way to fix it. I have a Python 2.6 script > that reads my Outlook 2010 task list. I'm able to read the tasks from > Outlook and store them as a list of objects without a hitch. But when > I try to print the tasks' subjects, one of the tasks is generating an > error: > > Traceback (most recent call last): > File "outlook_tasks.py", line 66, in > my_tasks.dump_today_tasks() > File "C:\Users\Anders\code\Task List\tasks.py", line 29, in > dump_today_tasks > print task.subject > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in > position 42: ordinal not in range(128) > > (where task.subject was previously assigned the value of > task.Subject, aka the Subject property of an Outlook 2010 TaskItem) > > From what I understand from reading online, the error is telling me > that the subject line contains an en dash and that Python is trying > to convert to ascii and failing (as it should). > > Here's where I'm getting stuck. In the code above I was just printing > the subject so I can see whether the script is working properly. > Ultimately what I want to do is parse the tasks I'm interested in and > then create an HTML file containing those tasks. Given that, what's > the best way to fix this problem? > > BTW, if there's a clear description of the best solution for this > particular problem - i.e., where I want to ultimately display the > results as HTML - please feel free to refer me to the link. I tried > reading a number of docs on the web but still feel pretty lost. > You can always encode in a non-ASCII codec. `print task.subject.encode()` where is something that supports the characters you want e.g. latin1. The list of built in codecs can be found: http://docs.python.org/library/codecs.html#standard-encodings ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Right solution to unicode error?
[email protected] wrote: > > Le jeudi 8 novembre 2012 19:49:24 UTC+1, Ian a écrit : > > On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin > > > > wrote: > > > > > If I want the other characters to work I need to change the code page: > > > > > > O:\>chcp 65001 > > > Active code page: 65001 > > > > > > O:\>Q:\tools\Python33\python -c "import sys; > > > sys.stdout.buffer.write('\u03b1\n'.encode('utf-8'))" > > > α > > > > > > O:\>Q:\tools\Python33\python -c "import sys; > > > sys.stdout.buffer.write('\u03b1\n'.encode(sys.stdout.en > > > coding))" > > > α > > > > I find that I also need to change the font. With the default font, > > > > printing '\u2013' gives me: > > – > > > > The only alternative font option I have in Windows XP is Lucida > > Console, which at least works correctly, although it seems to be > > lacking a lot of glyphs. > > > > Font has nothing to do here. > You are "simply" wrongly encoding your "unicode". > Why would font not matter? Unicode is the abstract definition of all characters right? From that we map the abstract character to a code page/set, which gives real values for an abstract character. From that code page we then visually display the "real value" based on the font. If that font does not have a glyph for a specific character page (or a different glyph) then that is a problem and not related encoding. Unicode->code page->font > >>> '\u2013' > '–' > >>> '\u2013'.encode('utf-8') > b'\xe2\x80\x93' > >>> '\u2013'.encode('utf-8').decode('cp1252') > '–' > This is a mismatched translation between code pages; not font related but is instead one abstraction "level" up. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Writing game-state data...
Graham Fielding wrote:
>
> Hey, folks, me again!
>
> I've been puzzling over this for a while now:
>
> I'm trying to write data to a file to save the state of my game using the
> following function:
>
> def save_game():
> #open a new empty shelve (possibly overwriting an old one) to write the
> game data
> file_object = open('savegame.sav', 'wb')
> file['map'] = map
> file['objects'] = objects
> file['player_index'] = objects.index(player) #index of player in objects
> list
> file['inventory'] = inventory
> file['game_msgs'] = game_msgs
> file['game_state'] = game_state
> file['stairs_index'] = objects.index(stairs)
> file['dungeon_level'] = dungeon_level
> file.close()
>
> However, while 'savegame.sav' is created in the directory I specify, the
> function dies on file['map'] = map.
> This is the end of the stack trace:
>
>
> File "C:\Python Project\Roguelike.py", line 966, in save_game
> file['map'] = map
> TypeError: 'type' object does not support item assignment
>
`file` is the built-in for file objects. I would say you need
to use file_object[] instead, but it is a file object
and is not meant for this usage. You can write directly
to a file but it is easier to use sqllite or shelve/pickle
libraries. I will use shelve in my example since your code
is already doing something similar. Do not forget to
import shelve in your own code.
def save():
shelf = shelve.open('savegame.sav', protocol=2)
# Change pickle protocol if you use Python < 2.3
shelf['map'] = map
shelf['objects'] = objects
shelf['player_index'] = objects.index(player)
shelf['inventory'] = inventory
shelf['game_msgs'] = game_msgs
shelf['game_state'] = game_state
shelf['stairs_index'] = objects.index(stairs)
shelf['dungeon_level'] = dungeon_level
shelf.close()
> Now, the map is randomly generated -- could that be an issue?
>
Both "file" and "map" are built-in keywords and using those
names for you own variables is called shadowing a built-in.
Shadowing a built-in can be interesting and useful but should
be avoided. Also, it seems like save() is not in a class nor
having anything passed in; are all the game states variables
stored at the module level or something?
> Should I just scrap the current system and use pickle?
You are almost there, so I would not bother. Normally I would
use pickle over shelve; I have not needed any of the advantages
of shelve and why use a library on top of pickle when I only
need pickle? Of course, YMMV.
~Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list
RE: duck typing assert
Andriy Kornatskyy wrote: > > Thank you for all comments. > > > It makes very good sense to say: > > > > duckmatch(IFoo).compare(Foo) > > Since we do duck match of IFoo... but there is no `duck match`, there is > `duck test`. I believe instead of > `compare` is more readable with `equals`. Than it is more from mathematics - > precise answer... that you can not > guarantee at all in dynamic programming language. So it false to use such > wording to reflect this check. We can > only make an assumption that one looks like the other (similar)... with some > limitation of cause... > understanding what is `duck test`. > > http://en.wikipedia.org/wiki/Duck_test > > The intent is to make such language `construct` so it reads as English > sentence that make sense, and not > mandatory `pythonic` way (readability counts, java smokes aside). > > is_similar(Foo).to(IFoo) # <= but we lost `duck test` sense here? > > Words `looks` and `like` are coming from duck test and point also direction: > > # 1 > looks(Foo).like(IFoo, notice=['__len__'], ignore_funcs=['foo'], > ignore_argspec['bar']) > > English sentence equivalent: if functions in Foo looks like one in IFoo than, > probably, IFoo can be replaced > with Foo; notice to check __len__, it is safe to ignore function `foo` and > arguments passed to `bar`. > > # 2 > looks(Foo, notice=['__len__'], ignore_funcs=['foo'], > ignore_argspec['bar']).like(IFoo) > > English sentence equivalent: while looking at Foo notice to check `__len__`, > it is safe to ignore function `foo` > and arguments passed to `bar`, than probably it like IFoo. What about? duck(Foo).equivalent_to(IFoo, ) duck(Foo).matches(IFoo, ) This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
