RE: Using the MSI installer on Windows: Setting PATH and Setuptools

2013-09-19 Thread Prasad, Ramit
cyt...@m.allo.ws wrote:
 Hello All,
 
 I really hate Windows, and I have only intermittent access to Windows 
 machines right now.
 
 When I install Python 2.7 on Windows using the MSI installer, it definitely 
 does not modify the PATH
 variable. So I modify the PATH variable myself as follows:
 
 setx PATH %PATH%;C:\Python27\
 
 Question 1: The command above requires a reboot in order to take effect, at 
 least on Windows 8. How do
 I make it take effect immediately? Maybe if I repeat the same command again 
 with 'set' instead of
 'setx'? Does 'set' affect the whole machine, or only the current CMD.EXE 
 session?

Set affects current session only.


Setx provides the only command-line or programmatic way to directly and 
permanently set system environment values. System environment variables are 
manually configurable through Control Panel or through a registry editor. The 
set command, which is internal to the command interpreter (Cmd.exe), sets user 
environment variables for the current console window only.
 ~ http://technet.microsoft.com/en-us/library/cc755104.aspx

Setx should not require a reboot, but might require user 
to log out and back in (or restart CMD). Also, note that
it modifies local environment by default and not system
environment.

[snip]

 
 Question 3: Does the Windows MSI installer from Python.org include 
 Setuptools? python-guide.org
 implies that it does not include Setuptools, but I have never needed to 
 manually install Setuptools, I
 am always able to use easy_install right away. Is my memory warped, or 
 perhaps tainted by old Python
 installs on the same machine?

ActiveState's ActivePython MSI does include pip. FAQ says 
it also includes distribute which you could remove 
(I am guessing) but it will stop PyPM from working. 
I believe they also setup the PATH for you. I think
ActivePython might be a slightly better installer for
Windows users--at least that is what some people have 
recommended. I have not tried it myself, but it might
be worth taking a look.

 
 Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the 
 best way to install it
 from the command line in a future-proof manner (on Windows)? I am imagining 
 something like this:
 
 wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
 python ez_setup.py
 
 However, (1) wget is not a Windows command. What is the Windows command? And 
 (2) is that URL the best
 possible URL? Or will that URL only download an old version, and there is a 
 better URL for new
 versions?

The pip documentation uses the URL 
https://raw.github.com/pypa/pip/master/contrib/get-pip.py

pip documentation: https://pip.readthedocs.org/en/latest/installing.html 
 
 
 Thank you,
 
 Zak


~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.  
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Help please, why doesn't it show the next input?

2013-09-11 Thread Prasad, Ramit
William Bryant wrote:
 Sent: Wednesday, September 11, 2013 2:32 PM
 To: python-list@python.org
 Subject: Re: Help please, why doesn't it show the next input?
 
 @Dave Angel
 
 What is .lower() ?

Thanks for bottom posting and trimming, but you should
leave some content quoted for context. Otherwise
people will not what you are referring to.

You can find answers to questions like this in the API.
http://docs.python.org/2/library/stdtypes.html#str.lower

I would recommend taking time to get familiar with the
Athena interpreter. It can also answer questions like
this (but with less detail than the web API).

You can use dir() to find the attributes on any object.
help() will give you docstring for the attribute/class.

 'A'.lower()
'a'
 help(''.lower)
Help on built-in function lower:

lower(...)
S.lower() - string

Return a copy of the string S converted to lowercase.

 help(dir)
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) - list of strings

If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the 
attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
  for a module object: the module's attributes.
  for a class object:  its attributes, and recursively the attributes
of its bases.
  for any other object: its attributes, its class's attributes, and

recursively the attributes of its class's base classes.
 dir('')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__getitem_\
_', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', 
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__\
', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', 
'__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclass\
hook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 
'center', 'count', 'decode', 'encode', 'endswith', 'expan\
dtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 
'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lo\
wer', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 
'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'starts\
with', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

If you want to see all the relevant information you can use help()
on the class [e.g. help(str)]. I think help(class) will not show
functions that start with _ unless they are python magic dunder 
functions (e.g. __str__).



~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.  
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Language design

2013-09-11 Thread Prasad, Ramit
Mark Janssen wrote:
 1) It tried to make Object the parent of every class.  No one's close
 enough to God to make that work.
 2) It didn't make dicts inherit from sets when they were added to Python.
 3) It used the set literal for dict, so that there's no obvious way to
 do it.  This didn't get changed in Py3k.
 4?) It allowed [reference] variables to be used as dict keys.  This
 creates a parsing difficulty for me, mentally.  Keys should be direct,
 hashable values, not hidden in a variable name.

What do you mean by 4? Do you mean that keys should only be hardcoded?
I am going to assume you meant something different, as that sounds like
a terrible idea to me...

 
 A few of the top of the head
 
 Mark

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.  
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: sax.handler.Contenthandler.__init__

2013-08-30 Thread Prasad, Ramit
Neil Cerutti wrote:
 This code is from The Python Cookbook, 2nd edition, 12.2 Counting
 Tags in a Document:
 
 from xml.sax.handler import ContentHandler
 import xml.sax
 class countHandler(ContentHandler):
 def __init__(self):
 self.tags={}
 def startElement(self, name, attr):
 self.tags[name] = 1 + self.tags.get(name, 0)
 
 Isn't overriding __init__ a risky thing to do? The docs don't
 mention it as a method I should override, and also don't define
 what's in there or if I'd need to call the base class __init__.
 Moreover, startDocument is provided for parser setup.
 
 As it happens, ContentHandler.__init__ isn't empty, so the above
 code could fail if the parser isn't prepared for _locator to be
 undefined.
 
 Is the above code is an acceptable idiom?
 
 --
 Neil Cerutti
 --

I think this is a bad idea unless you want to avoid the parent 
class __init__ specifically (in which case a comment stating 
why is mandatory). I do not like that this recipe shows behavior
that might be fine in this instance, but is not a good general 
practice.

 def __init__(self):
 super(ContentHandler, self).__init__()
 #OR ContentHandler.__init__(self)
 self.tags={}

I personally think the super() line is better of the two options.

~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: subprocess.Popen instance hangs

2013-08-29 Thread Prasad, Ramit
Tim Johnson
 using Python 2.7.1 on OS X 10.7.5
 
 I'm managing a process of drush using an instance of subprocess.Popen
 
 The process has a '--verbose' option. When that option is passed as
 part of the initializer `args' argument, the process will hang.
 
 It should be no surprise as drush output with the --verbose option
 can be _extremely_ verbose, and I can do without it, but I would
 like to learn how to handle it. I've googled this topic, but my poor
 little brain is yet to sort out all of the content found.
 
 ## my relevant code follows :
 p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
 ## wait() is 'forever' if '--verbose' used
 exit_status = p.wait()
 output = p.stdout.read()
 ## done
 
 I 'suspect' that using a tempfile may be the solution, if so, I
 could use some examples.
 
 thanks
 --
 Tim
 tim at tee jay forty nine dot com or akwebsoft dot com
 http://www.akwebsoft.com
 --


I think the documentation covers your issue. 


Popen.wait()
Wait for child process to terminate. Set and return returncode attribute.
Warning: will deadlock when using stdout=PIPE and/or stderr=PIPE and the 
child 
process generates enough output to a pipe such that it blocks waiting for 
the 
OS pipe buffer to accept more data. Use [Popen.]communicate() to avoid that.
 From http://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait

Does switching to `p.communicate()` solve your problem?


~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: [error] [client 178.59.111.223] (2)No such file or directory: exec of

2013-08-28 Thread Prasad, Ramit
Ferrous Cranus wrote:
 Yes Uli, the script metrits.py is being invoked by Apache Web Server which in 
 turn runs under user
 Nobody.
 So, that mean that? user 'nobody' has no write permission to /home/nikos 
 folder?

Yes. You should make it group writable with nobody as the group. Use chmod 
and chown
to change permissions and owners (i.e. groups). As a last resort (for testing 
purposes
only!) you can set the directory world writable, but then *anyone* with 
access to that
host can write/delete/destroy the contents of that directory. This is obviously
very insecure and not a good idea. But if you are only trying to get a quick 
error message
then it might work for you. 

Normally I would have thought you would have a public_html or www directory in 
your
home folder that would be readable/writable to the web server (and where you 
should 
write).


~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: Can a child access parent attributes if that child added post-hoc as an attribute to the parent?

2013-08-27 Thread Prasad, Ramit
Ian Kelly wrote:
 On Thu, Aug 22, 2013 at 3:26 PM, Prasad, Ramit
 ramit.pra...@jpmorgan.com.dmarc.invalid wrote:
  Bitswapper wrote:
 
  So I have a parent and child class:
 
 
  class Map(object):
  def __init__(self, name=''):
  self.mapName = name
  self.rules = {}
 
  class Rule(Map):
  def __init__(self, number):
  Map.__init__(self)
  self.number = number
 
  This means that rules will never have a name. I think you need
def __init__(self, name='', number=None):
Map.__init__(self, name)
self.number = number
 
 No, that's still wrong.  The OP talks abut maps having names, not
 rules having names.  Unless a Rule is-a Map, which sounds unlikely,
 Rule should not be inheriting from Map in the first place.
 

Good point. Composition definitely makes more sense as I was
confused by how the inheritance was supposed to work anyway. :)


~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: Can a child access parent attributes if that child added post-hoc as an attribute to the parent?

2013-08-22 Thread Prasad, Ramit
Bitswapper wrote:
 
 So I have a parent and child class:
 
 
 class Map(object):
 def __init__(self, name=''):
 self.mapName = name
 self.rules = {}
 
 class Rule(Map):
 def __init__(self, number):
 Map.__init__(self)
 self.number = number

This means that rules will never have a name. I think you need
  def __init__(self, name='', number=None):
  Map.__init__(self, name)
  self.number = number
 
 def __repr__(self):
 return Map  + self.mapName +  rule number  + str(self.number)
 
 if __name__ == __main__:
   map = Map(thismap)
   rule = Rule(1)
   map.rules[rule.number] = rule
 
 
 
 with the above:
 $ python -i inherit.py
  map
 __main__.Map object at 0xb7e889ec
  map.rules
 {1: Map  rule number 1}
  map.rules[1]
 Map  rule number 1
 
 
 
 I have tried adding:
   map.rules[2] = Rule(2)
 
 but that still gets:
 
 $ python -i inherit.py
  map.rules
 {1: Map  rule number 1, 2: Map  rule number 2}
 
 
 and:
 map.rule = Rule(3)
 
 which also doesn't really get me what I'm looking for:
 
  map.rules
 {1: Map  rule number 1, 2: Map  rule number 2}
  map.rule
 Map  rule number 3
 
 
 
 It seems to me what I'm trying to do is link an arbitrary child instance to 
 an arbitrary instance of a
 parent class, which in this case would be handy  Because I'd like to populate 
 a map with rules and
 print the rules including the parent map name for each rule.  I'm just not 
 sure how I would go about
 doing this in python.
 
 Any thoughts are welcome, and thanks in advance

I not sure what you mean by the above. Can you provide an example of what you 
want
to occur and the output for it?


~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: Unpickling data with classes from dynamic modules

2013-08-21 Thread Prasad, Ramit
Fredrik Tolf wrote:
 
 Dear list,
 
 I have a system in which I load modules dynamically every now and then
 (that is, creating a module with types.ModuleType, compiling the code for
 the module and then executing it in the module with exec()), and where I
 would wish to be able to have classes in those modules containing classes
 that could pickled, and then unpickled again.
 
 The problem with that, currently, is of course two-fold: The dynamically
 loaded module may not be loaded at the time when the unpickling takes
 place, but even if it were, it isn't registered in sys.modules, so the
 unpickler can't find it either way. And, of course, that is detected
 already when pickling.
 
 Is there any way to fix this, at all?
 
 I considered trying to create subclasses of the pickler and unpickler that
 pickle a reference to a module loader and data for the particular module
 along with a class that comes from such a module, by overriding
 Pickler.save_global and Unpickler.load_global. Unfortunately, however,
 those functions aren't part of the public interface and can't be
 overridden when the C-pickle module is used instead (which, obviously, is
 what normally happens).
 
 Is there any way around this without having to modify the pickle module
 itself?
 
 --
 
 Fredrik Tolf
 --

I believe rather than subclassing the pickler, you are expected to 
change the behavior from within the class via __getstate__ and __setstate__.

http://docs.python.org/2/library/pickle.html#object.__getstate__

Although, for your use case (loading unknown classes) the section on pickle and 
extension types may be more appropriate.

http://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types

Maybe all you need to add is implementation for obj.__reduce__


~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: utcoffset v. _utcoffset

2013-08-21 Thread Prasad, Ramit
Skip Montanaro wrote:
 
 Consider this little Python script:
 
 import dateutil.parser
 import pytz
 
 x = dateutil.parser.parse(2013-08-16 23:00:00+01:00)
 localtz = pytz.timezone(America/Chicago)
 y = localtz.normalize(x)
 
 When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
 traceback:
 
 Traceback (most recent call last):
   File /home/skipm/tmp/localtzex.py, line 8, in module
 y = localtz.normalize(x)
   File /opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py,
 line 233, in normalize
 offset = dt.tzinfo._utcoffset
 AttributeError: 'tzoffset' object has no attribute '_utcoffset'
 
 Looking at the tzinfo attribute, I see that it has utcoffset, but
 not _utcoffset.  I realize those are the latest, most up-to-datest
 versions of all three elements.  I'm having trouble updating dateutil
 and pytz on my Mac at home (stuck on even older versions).  Can
 someone with newer versions of dateutil and pytz see if this problem
 is still present?
 
 Thx,
 
 Skip
 --

Using Python 2.6, dateutil 1.5, pytz 2013b


Snipped from the documentation of pytz via help(localtz.normalize)
''' 
Correct the timezone information on the given datetime

If date arithmetic crosses DST boundaries, the tzinfo
is not magically adjusted. This method normalizes the
tzinfo to the correct one.
'''

Going from +1 to +6 will not cross the DST boundary.

The documentation for localtz.normalize (in pytz 2013b) has a sample 
of what to do if it does cross DST which seems to boil down to using 
datetime.astimezone() and then localtz.normalize() if your date 
arithmetic crosses DST.

 import dateutil.parser
 import pytz
 x = dateutil.parser.parse(2013-08-16 23:00:00+01:00)
 localtz = pytz.timezone(America/Chicago)
 x.astimezone( localtz )
datetime.datetime(2013, 8, 16, 17, 0, tzinfo=DstTzInfo 'America/Chicago' CDT-1 
day, 19:00:00 DST)


~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: refresing the edited python function

2013-08-20 Thread Prasad, Ramit
alex23
 
 On 19/08/2013 10:55 AM, Sudheer Joseph wrote:
  I have been using ipython and ipython with qtconsole and working on a
  code with functions. Each time I make a modification in function
  I have to quit IPTHON console (in both with and with out qt console )
  and reload the function freshly. If I need to see the changed I made in
  the function. I tried below options
 
  del function name
  import the module again  by issuing from xxx.py import yy
 
 This doesn't re-import the module if xxx has already been imported. It
 simply rebinds xxx.yy to yy.
 
  import xxx.py
 
 This also doesn't re-import the module if it has already been imported.
 
 When you import a module, or a function from a module, a module object
 is created and stored in sys.modules. Any subsequent 'import module'
 calls will return a reference to that module object, and won't reload
 from file at all.
 
 You can easily verify this by creating a test module 'foo' with a single
 line of `print('loading foo')` and then trying this from the console:
 
  In [1]: import foo
  loading foo
 
  In [2]: del foo
 
  In [3]: import foo
 
  In [4]:
 
 Note that you only see 'loading foo' the first time you import the
 module. In order to have the module loaded again rather than returning
 the existing reference, you would use `reload(foo)`:
 
  In [5]: reload(foo)
  loading foo
 
 So: in order to be able to use functions from a re-loaded module, you
 should always refer to them via the module object, and not import them
 directly:
 
   import xxx
   xxx.yy() # original code
  # ...modify function `yy` in your source file
   reload(xxx)
   xxx.yy() # new code
 
 Or: you can reload the module and then rebind the functions:
 
   from xxx import yy
   yy() # original code
  # ...modify function `yy` in your source file
   reload(xxx)
   from xxx import yy
   yy() # new code
 
 Hope this helps.
 
 --

In Python 3 the reload built-in was moved to the imp module.
So use imp.reload(module) instead.


~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: PEP 450 Adding a statistics module to Python

2013-08-16 Thread Prasad, Ramit
CM wrote:
 
 On Friday, August 9, 2013 9:10:18 PM UTC-4, Steven D'Aprano wrote:
  I am seeking comments on PEP 450, Adding a statistics module to Python's
  standard library:
 
 I think it's a very good idea.  Good PEP points, too.  I hope it happens.
 

+1 especially for non-Cpython versions of 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: Verifying Variable value

2013-08-14 Thread Prasad, Ramit
chandan kumar wrote:

 Hi ,
 
 Is there a way to validate variable values while debugging any python 
 code.Run below example  in
 debugging mode and i would like to know the value of c (I know print is an 
 option) with any other
 option other than printing.
 In C# or some other tools we can verify each statement and values. Is there 
 way to check each
 statement in python code like in c#.
 
 Ex:
 def method()
   a = 20
   b =30
   c =  a + b
 
 
 Best Regards,
 Chanadn

In addition to pdb, I would imagine most Python IDEs would support debugging in 
this manner.

pydev: http://pydev.org/manual_adv_debugger.html
Wing: http://wingware.com/wingide/debugger
Pycharm: http://www.jetbrains.com/pycharm/webhelp/running-and-debugging.html

This actually has a nice table of some IDEs for Python. See which ones
have a 'Y' under the PD column.
http://stackoverflow.com/questions/81584/what-ide-to-use-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: Could you verify this, Oh Great Unicode Experts of the Python-List?

2013-08-13 Thread Prasad, Ramit
Michael Torrie wrote:
 On 08/11/2013 11:54 PM, Gregory Ewing wrote:
  Michael Torrie wrote:
  I've always wondered if the 160 character limit or whatever it is is a
  hard limit in their system, or if it's just a variable they could tweak
  if they felt like it.
 
  Isn't it for compatibility with SMS? Twitter could
  probably change it, but persuading all the cell phone
  networks to change at the same time might be rather
  difficult.
 
 Yes I think you're correct about it being limited for SMS.
 
 However I know of no phone or network that won't let you use longer
 messages; multiple SMS packets are used and most phone paste them back
 together.  So no there's nothing that anyone needs to change to use
 longer messages if they so chose.  It's now just an arbitrary limit,
 part of the twitter culture.


True, but order of delivery is not guaranteed. I still sometimes
get out of order text message when multiple messages are sent
at once.


~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: Python3 Multiprocessing

2013-08-09 Thread Prasad, Ramit
Devyn Collier Johnson
 On 08/09/2013 03:44 PM, MRAB wrote:
  On 09/08/2013 20:30, Devyn Collier Johnson wrote:
[snip]
 
  jobs1.join()
  jobs2.join()
 
 
 Thanks MRAB! That is easy. I always (incorrectly) thought the join()
 command got two threads and made them one. I did not know it made the
 script wait for the threads.
 

It does join two threads, just not the threads you think! It joins
a child thread with the parent thread and not two children thread.

 Mahalo,
 
 devyncjohn...@gmail.com
 --


~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: Newbie: static typing?

2013-08-08 Thread Prasad, Ramit
Rui Maciel wrote:
 Chris Angelico wrote:
 
  On Tue, Aug 6, 2013 at 10:01 AM, Rui Maciel rui.mac...@gmail.com wrote:
  It would be nice if some functions threw an error if they were passed a
  type
  they don't support or weren't designed to handle.  That would avoid
  having to deal with some bugs which otherwise would never happen.
 
  To avoid this sort of error, I've been testing arguments passed to some
  functions based on their type, and raising TypeError when necessariy, but
  surely there must be a better, more pythonic way to handle this issue.
 
  def add_three_values(x,y,z):
  return x+y+z
 
  Do you want to test these values for compatibility? Remember, you
  could take a mixture of types, as most of the numeric types can safely
  be added. You can also add strings, or lists, but you can't mix them.
  And look! It already raises TypeError if it's given something
  unsuitable:
 
 If the type problems aren't caught right away when the invalid types are
 passed to a function then the problem may only manifest itself in some far
 away point in the code, making this bug needlessly harder to spot and fix,
 and making the whole ordeal needlessly too time consuming.
 
 
 Rui Maciel

This can be true, but in personal experience does not happen 
often. I will say that dynamic typing ends up usually
being more future proof as I can later create a similar object
(but not in the same inheritance hierarchy) that will work
with older functions because the functions don't look for
certain types but rather just rely on duck typing.

I find this especially useful when testing or mocking. I can
create a test object and attach methods/attributes to the
test object to duck type as I desire to test the my desired code. 

I think the following reads are very interesting
for people new to Python from other languages (not just Java).
http://dirtsimple.org/2004/12/python-is-not-java.html
(and the flip side) http://dirtsimple.org/2004/12/java-is-not-python-either.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: PEP8 79 char max

2013-07-31 Thread Prasad, Ramit
Grant Edwards wrote:
 On 2013-07-31, Neil Cerutti ne...@norwich.edu wrote:
 
  Besides, after studying The Pragmatic Programmer I removed nearly
  all the tables from my code and reference them (usually with csv
  module) instead.
 
 I don't understand.  That just moves them to a different file --
 doesn't it?  You've still got to deal with editing a large table of
 data (for example when I want to add instructions to your assembler).
 
 --
 Grant Edwards   grant.b.edwardsYow! Spreading peanut
   at   butter reminds me of
   gmail.comopera!!  I wonder why?
 --

True, but a CSV file is easy to edit in something like a spreadsheet
application (LibreOffice/MS Office); alignment becomes automatic
then.


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: Using system python vs. updated/current version

2013-07-31 Thread Prasad, Ramit
memilanuk wrote:
 Hello there,
 
 What would be considered the correct/best way to run a current release
 of python locally vs. the installed system version?  On openSUSE 12.3,
 the repos currently have 2.7.3 and 3.3.0.  As far as I know, I'm not
 really hitting any limitations with the existing versions - my skills
 just aren't that far along - so its not a burning 'need' but I'm still
 curious/interested in the topic.

You should be able to install both Python 2 and 3 in most modern
Linux distributions (at the same time). I would not change the system
Python version.

If you are not blocked from running Python 3 by some necessary
dependency then you should use it. Otherwise, use the most
recent Python version you can. 

 
 Also... in some places in the 'Net I see references to installing
 everything 'locally' via pip, etc. in virtualenvs and not touching the
 system installed version of python... yet most linux distros seem to
 have many/most such packages available in their package repos, which
 seems like it'd be easier to install via the package manager and let it
 keep things updated.  Could someone touch on what they feel the pros and
 cons would be either way?

Virtual envs are great if you work on multiple projects and want to 
keep each project's dependencies separate and manageable. This
will let you change dependencies to a newer version based on project 
rather than having to change the dependency for all projects.

Not to mention this also allows you to install packages on hosts
that you do not have access to install them to the system
packages directory.

On a personal machine, I would install some things like pip/virtualenv 
(/numpy maybe) to system packages directory but keep most packages in 
a project specific directory (i.e. virtualenv).


 
 Thanks,
 
 Monte



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: pcurl and network connection's problem

2013-07-31 Thread Prasad, Ramit
sam319 wrote:
 I am having problems with pycurl in my threads , when i run it , it does 
 correctly but some times the
 connection has been established but nothing will be downloaded and the 
 threads stay alive without
 doing any thing (especially when the network's speed is slow and has aborted 
 status) .
 
 i can't use TIMEOUT  because i don't have the max time for downloading
 
 how can i solve this problem in python

So you want to wait hours/days/years for a failed download? You should always 
set a 
timeout that is sane. If you anticipate network slowness, then set your timeout 
to 
something larger like 2-3 minutes. IIRC, the timeout only affects connection
establishment so that will not help out your use case but I want to emphasize
that you always want a timeout to be set. 

Pycurl has an option for LOW_SPEED_LIMIT/LOW_SPEED_TIME which should allow you 
to set 
a minimum transfer speed which will abort the transfer. This should solve your 
problem
where the connection is created but nothing is being downloaded.

See: 
http://stackoverflow.com/questions/4960021/handle-pycurl-hang-on-twitter-streaming-api


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

2013-07-26 Thread Prasad, Ramit
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 change
 a string 01112345 into a list so that it does that automatically when the 
 user clicks 'run'.

This really does not make sense to me. Does that mean 0, 1, 11, 23, 45 or 0, 
111, 2345 or 0,11, 
2345 or something else entirely? If you are doing this on the shell I would 
have the 

RE: Python Script Hashplings

2013-07-26 Thread Prasad, Ramit
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

2013-07-26 Thread Prasad, Ramit
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 stdin, line 1, in module
   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: Python 3: dict dict.keys()

2013-07-25 Thread Prasad, Ramit
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

2013-07-25 Thread Prasad, Ramit
Chris Angelico wrote:
 On Fri, Jul 26, 2013 at 5:07 AM,  wxjmfa...@gmail.com 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: Python 3: dict dict.keys()

2013-07-24 Thread Prasad, Ramit
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: im.py: a python communications tool

2013-04-12 Thread Prasad, Ramit
Mark Janssen wrote:
  It doesn't have to say so, if it's not charging any money -- there's no
  expectation that you're getting anything at all!
 
  Of course there is. If Oprah Winfrey stands up and publicly says that
  she's giving you a car, FOR FREE, no strings attached, and then gives you
  a piece of old bubblegum, you have standing to sue for breach of promise.
  If she gives you the car, but puts it down as a *prize* rather than a
  gift, then there is a big, hefty string attached: income tax.
 
 But you see, there's the critical difference.  First of all you're
 making two errors in your comparison.  Firstly, a *person* is saying
 that she's going to *do something for you*.  She's making a promise.
 If I put a piece of software online -- you're taking it!  That's #1
 (!)

Theoretically isn't putting a piece of software online akin to
publishing it? Following that logic, then there is the possibility 
of arguing an implicit promise that the software does what it is 
supposed to. Any bugs would be the responsibility of the developer. 

On a separate note, even if the judgment supports your view
and the developer is never responsible for damages, will you
still not be responsible for any court/lawyer fees? And
getting those fees paid by suitor will likely be another court 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: newbie question about confusing exception handling in urllib

2013-04-12 Thread Prasad, Ramit
Steven D'Aprano wrote:
 try:
 main()
 except Exception as err:
 log(err)
 print(Sorry, an unexpected error has occurred.)
 print(Please contact support for assistance.)
 sys.exit(-1)
 
 

I like the traceback[0] module for logging last exception thrown.
See traceback.format_exc() or traceback.print_exc().

trace = traceback.format_exc()
log.error('I was trying to do action, but unexpected 
error.\n{0}'.format(trace))

[0] http://docs.python.org/2/library/traceback.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: extract HTML table in a structured format

2013-04-12 Thread Prasad, Ramit
Jabba Laci
 Hi,
 
 I wonder if there is a nice way to extract a whole HTML table and have the 
 result in a nice structured
 format. What I want is to have the lifetime table at the bottom of this page:
 http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with a 
 script until when my
 Ubuntu release is supported).
 
 I could do it with BeautifulSoup or lxml but is there a better way? There 
 should be :)
 

I know you already answered your question, but thought this might be helpful
in the future.

Wikipedia has an API for programmatic access.
http://www.mediawiki.org/wiki/API 


~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: im.py: a python communications tool

2013-04-12 Thread Prasad, Ramit
Neil Cerutti wrote:
 On 2013-04-12, Mark Janssen dreamingforw...@gmail.com wrote:
  Possibily, but don't accept this view of the legal system.
  Judges can be quite reasonable.  They don't want more time
  taken for bullshit cases and would much prefer for things to be
  settled (that is what their duty is -- to settle matters, not
  to make lawyers wealthy).
 
 Wishful thinking is the wrong way to approach any legal matter.
 

He is not completely wishful (for USA). 
http://www.macrumors.com/2013/04/11/u-s-judge-expresses-frustration-at-apples-and-googles-use-of-litigation-as-business-strategy/

Of course, not sure if the frustration will actually lead to
an action or is just idle talk.


~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: amazing scope?

2012-11-30 Thread Prasad, Ramit
andrea crotti
 
 I wrote a script, refactored it and then introducing a bug as below:
 
 def record_things():
 out.write(Hello world)
 
 if __name__ == '__main__':
 with open('output', 'w') as out:
 record_things()
 
 
 but the shocking thing is that it didn't actually stopped working, it
 still works perfectly!
 
 What my explanation might be is that the out is declared at module
 level somehow,
 but that's not really intuitive and looks wrong, and works both on
 Python 2.7 and 3.2..

Makes sense to me. `out` is declared in an if statement. If statements
have no scope and it is not in a function so it gets added to the 
module's namespace.


~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: pyHook and time libraries

2012-11-30 Thread Prasad, Ramit
Doron wrote:
 
 Hey, I'm tring to create a software that records the keyboard/mouse and sends 
 email of the log every
 predetermined period.
 
 I've manage to make the recorder and the auto-email sender, but I still can't 
 make both of them work
 simultaneously.
 
 Can someone help me with this please?
 I thought about threading but again... It just sends blank mails without the 
 logs.
 
 Thanks alot ahead!

I am not sure how to even begin helping you. I do not even know
what is wrong other than can't make both of them work simultaneously.
What version of Python and OS? Are you using any 3rd party modules?
What is the code you use? What happens and what do you expect? How
are you getting the logs for email? Are they being passed in or are
you using a log file?


~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: please help me to debud my local chat network program

2012-11-30 Thread Prasad, Ramit
Minh Dang wrote:
 
 can anyone help me?

Chris Angelico has given you some good comments which
should give you a direction to investigate.

This list is a global list and you seem a tad impatient. It is normal
to hear back from a few hours to a day or two. 

Even if I wanted to help, without context in this email I might not
know what you need help with. I could probably look it up in an 
archive of the list, but it is unlikely I will. Help yourself
by keeping relevant text in the email and respond inline (or below)
the quoted text. 

That being said, did Chris's suggestion work? If not what happened?


~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.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Ramit Prasad wrote:
 
 Dennis Lee Bieber wrote:
 
  Unless there has been a major change in the parser... (I still don't
  have Python 3.x installed)
 
  I believe tab is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
  8...
 
 A tab is *one* character. Your *editor* may show tabs visually
 expanded or convert them to spaces. This is entirely editor dependent.
 My current (python) editor, does expands tabs to the next *multiple* of 4.
 It helps keep code aligned, and I have no need for 4 hard spaced tabs
 without regards to alignment (yet). I have had editors that did 4 hard
 spaced tabs, so it might be a developer/application preference.
 
  with open(r'c:\ramit\mix_tab_space.txt')as f:
 ... d = f.read()
 ...
  print repr(d)
 '\tblah\ntest\n\t'
  print d[0] + 'goo'
   goo
  print repr(d[0] + 'goo')
 '\tgoo'

Apologies, I missed that it was talking about the parser
and not editor/file. Please disregard my previous post. 


~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: Imaging libraries in active development?

2012-11-29 Thread Prasad, Ramit
Christian Heimes wrote:
 
 Am 28.11.2012 19:14, schrieb Michael Torrie:
  I'm curious.  What features do you need that pil doesn't have?  Other
  than updating pil to fix bugs, support new image types or new versions
  of Python, what kind of active development do you think it needs to
  have? Maybe pil has all the features the original author wanted and is
  pretty stable.  To judge a package on how fast it's changing seems a bit
  odd to me.  Obviously you want to know that bugs can get fixed of
  course.  Perhaps none have been reported recently.
 
 PIL is missing a bunch of features like proper TIFF support (no
 multipage, g3/g4 compression and more), JPEG 2000, RAW and HDR image
 formats, tone mapping, proper ICC support, PEP 3128 buffer support ...
 
 PIL is also rather slow. My smc.freeimage library can write JPEGs about
 six times faster, because it uses libjpeg-turbo. Only some Linux
 distributions have replaced libjpeg with the turbo implementation.
 

Have you tried libtiff? I believe the author may read this list.
(He posted here for at least one release). 
http://code.google.com/p/pylibtiff/


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: re.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Dennis Lee Bieber wrote:
 
   Unless there has been a major change in the parser... (I still don't
 have Python 3.x installed)
 
   I believe tab is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
 8...

A tab is *one* character. Your *editor* may show tabs visually 
expanded or convert them to spaces. This is entirely editor dependent. 
My current (python) editor, does expands tabs to the next *multiple* of 4. 
It helps keep code aligned, and I have no need for 4 hard spaced tabs 
without regards to alignment (yet). I have had editors that did 4 hard 
spaced tabs, so it might be a developer/application preference.

 with open(r'c:\ramit\mix_tab_space.txt')as f:
... d = f.read()
...
 print repr(d)
'\tblah\ntest\n\t'
 print d[0] + 'goo'
goo
 print repr(d[0] + 'goo')
'\tgoo'

 
   So the first is 8+4 = 12 spaces, the second is 2+8+4 = 14 spaces.
 
   Does 2 + tab + 2 vs 4 + tab vs tab + 4 succeed? That would
 confirm the treatment.
 
   The main concern with mixed tab and spaces, as I recall, was due to
 having /editors/ and /terminals/ configured to show tab as a four
 space (or anything other than an eight space) increment; so visually
 four spaces and one tab might look the same... One user might have the
 editor showing 4-space indents on tab but entering text using 4 spaces
 on input -- which now is mis-aligned if the source file HAD tab in it.


~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: Compare list entry from csv files

2012-11-29 Thread Prasad, Ramit
Anatoli Hristov wrote:
 Hello,
 
 Tried to document a little bit the script, but I'm not that good in that too 
 :)
 
 The only problem I have is that I cant compare other field than the
 first one in
 for ex_phone in phones:
 telstr = ex_phone[0].lower()
 When I use telstr = ex_phone[0].lower() it says out of range and the
 strange think is that the range is 6 I can't figure that out. So when
 I edit the csv I modify the look of the file and then I start the
 script and it works, but I wanted to use more than one condition and I
 can't :(
 
 

Can you print ex_phone first. You are opening the files in text mode
so I wonder if the line endings are causing you to read and extra
line in between. Can you try reading the csv as rb instead of 
rt?

 
 
 import csv
 
 # Open the file with the names and addresses
 origf = open('c:/Working/vpharma.csv', 'rt')
 # Open the  file with the phone numbers
 secfile = open('c:/Working/navori.csv', 'rt')
 
 # Creates the empty list with the names
 namelist = []
 # Creates the empty list with the phone numbers
 PHONELIST = []
 
 
 # Reads the file with the names
 # Format Name,Phone
 names = csv.reader(origf, delimiter=';')
 
 # Reads the file with the phone numbers
 # Format First name,Lastname,Address,City,Country,Phone
 phones = csv.reader(secfile, delimiter=';')
 
 # Creates a list with phone numbers
 #for tel in phones:
 #PHONELIST.append(tel)
 
 
 def finder(Compare_Name,rows):
 '''
 Compare the names from the namelist with the names from the phonelist.
 If the name match - then the phone number is added to the specified field
 '''
 for ex_phone in phones:
 telstr = ex_phone[0].lower()
 print telstr
 if telstr.find(Compare_Name) = 0:
 print \nName found: %s % Compare_Name
 namelist[rows][-1] = ex_phone[-1].lower()
 else:
 print Not found %s % Compare_Name
 pass
 return
 
 def name_find():
 rows = 0
 for row in names:
 namelist.append(row)
 Compare_Name = row[1].lower()
 finder(Compare_Name,rows)
 rows = rows+1
 
 if __name__ == '__main__':
 name_find()
 
 # Writes the list to a file
 wfile  = open('c:/Working/ttest.csv', wb)
 writer = csv.writer(wfile, delimiter=';')
 for insert in namelist:
 writer.writerow(insert)
 wfile.close()


~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: os.popen and the subprocess module

2012-11-27 Thread Prasad, Ramit
Andrew wrote:
 
 Hello world,
 
 I'm working on a script that will run an executable obtaine the output
  from the executable
 and do some analysis on the output. Essentially the script runs the
 executable analyses
 the data.
 I'm looking into os.popen and the subprocess module, implementing os.popen
 is easy but i hear
 it is depreciating  however I'm finding the implemantation of subprocess
 daunting can anyone help
 

Have you read the documentation?

http://docs.python.org/library/subprocess.html#replacing-older-functions-with-the-subprocess-module
(specifically 17.1.4.5)

This may help as well.
http://www.doughellmann.com/PyMOTW/subprocess/#capturing-output

Note, use of shell=True is usually discouraged as it can be
unsafe.


~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: How to sort list of String without considering Special characters and with case insensitive

2012-11-27 Thread Prasad, Ramit
san wrote:
 
 Please let me know how to sort the list of String in either ascending / 
 descending order without considering
 special characters and case.
 ex: list1=['test1_two','testOne','testTwo','test_one']
 Applying the list.sort /sorted method results in sorted list ['test1_two', 
 'testOne', 'testTwo', 'test_one']
 but the without considering the special characters and case it should be
 ['testOne','test_one', 'test1_two','testTwo'] OR 
 ['test_one','testOne','testTwo', 'test1_two' ]
 
 list.sort /sorted method sorts based on the ascii value of the characters but 
 Please let me knwo how do i
 achieve my expected one

You can pass a key function into list.sort() and sorted(). This
allows you to customize the sorting. In the below examples
I use lambda but you can use a non-lambda function (if you need
more complexity).

Case insensitive searches are often done by converting the 
strings being compared into the same case. Here I turned
them all uppercase.

lst = ['test1_two', 'testOne', 'testTwo', 'test_one']
lst.sort(key=lambda x: x.upper())

This will filter non-alphanumeric characters. You may
be able to create and use a translation table instead.

lst.sort( key=lambda x: ''.join( c.upper() for c in x if c 
in string.letters+string.digits ) )


~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: Getting a seeded value from a list

2012-11-26 Thread Prasad, Ramit
Chris Angelico wrote:
 
 On Sat, Nov 24, 2012 at 3:27 AM, Prasad, Ramit
 ramit.pra...@jpmorgan.com wrote:
  Steven D'Aprano wrote:
 
  On Wed, 21 Nov 2012 14:41:24 +1100, Chris Angelico wrote:
 
   However, this still means that the player will see the exact same level
   regenerated every time, absolutely fresh. As previously stated in this
   thread, that's not usually a good thing for encounters, treasure, etc.
   Once some nasty critter has been killed, he should STAY killed! :)
 
  Why? That isn't true in real life, why should it be true for games?
 
 
  It is not true in all games. I have seen games where treasures
  regenerate in the same location except for key items. Same goes
  for enemies (where only bosses do not regenerate). It really
  just depends on the type of game you are playing--designing
  in this case.
 
 Perhaps they regenerate, but do they regenerate from the exact same
 random seed? For instance, in Murkon's Refuge, the maps are
 handcrafted and thus constant every time you enter a particular level
 - but go downstairs and upstairs, and the monsters and treasure
 regenerate, different from last time.
 
 Of course, if the idea is that you're rewinding time, then it makes
 good sense for you to see the exact same pattern of enemies.
 

Hmm. I guess most of the games where I remember regenerating
enemies are a bit older. Chrono Trigger had enemies that 
would regenerate if you left a map screen and came back, but
then again it seems more likely that the enemies were hard
coded and not generated at all. Either that or they [games] are
like Diablo/Castlevania where monsters are constantly generated.

I still hold the opinion that the seeding behavior depends on the 
game. I wonder what Nethack does?


~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: Getting a seeded value from a list

2012-11-23 Thread Prasad, Ramit
Steven D'Aprano wrote:
 
 On Wed, 21 Nov 2012 14:41:24 +1100, Chris Angelico wrote:
 
  However, this still means that the player will see the exact same level
  regenerated every time, absolutely fresh. As previously stated in this
  thread, that's not usually a good thing for encounters, treasure, etc.
  Once some nasty critter has been killed, he should STAY killed! :)
 
 Why? That isn't true in real life, why should it be true for games?
 

It is not true in all games. I have seen games where treasures
regenerate in the same location except for key items. Same goes
for enemies (where only bosses do not regenerate). It really 
just depends on the type of game you are playing--designing 
in this 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: Problem with subprocess.call and windows schtasks

2012-11-23 Thread Prasad, Ramit
Dave Angel wrote:
 
 On 11/20/2012 06:41 PM, Tom Borkin wrote:
 
 (Please don't top-post.  Now we lose all the context)
  Using shlex, I now have this:
  #!\Python27\python
  import os, subprocess
  path = os.path.join(C:\\, Program Files, Apache Group, Apache2,
  htdocs, ccc, run_alert.py)
  #subprocess.call(['SchTasks', '/Create', '/SC', 'ONCE', '/TN', 'test',
  '/TR', path, '/ST', '23:50'])
  subprocess.call(['SchTasks', '/Create', '/SC', 'ONCE', '/TN', 'test',
  '/TR', 'run_alert.py', '/ST', '23:50'])
  Both of the above commands throw the same error:
  ERROR: The filename, directory name or volume label syntax is incorrect.
 
 I don't use Windows, but doesn't a Windows program usually have an .exe
 extension?  So why would you expect it to find SchTasks ?  Adding
 extensions is a shell feature, and you're not using the shell.
 
 Also, you should take a look at the value path.  On Linux, it shows up as:
 
 C:\\/Program Files/Apache Group/Apache2/htdocs/ccc/run_alert.py
 
 It'll be different under Windows, but probably still wrong.

Windows 7 + Python 2.6
 os.path.join(C:\\, Program Files, Apache Group, Apache2,
...  htdocs, ccc, run_alert.py)
'C:\\Program Files\\Apache Group\\Apache2\\htdocs\\ccc\\run_alert.py'


~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: Index Error

2012-11-20 Thread Prasad, Ramit
Can you please post in plain text and stop top-posting? Thanks. 

inshu chauhan wrote:
 
 def distance(c, p):
     dist = sqrt(
     ((c[0]-p[0])**2) +
     ((c[1]-p[1])**2) +
     ((c[2]-p[2])**2)
     )
     return dist
 
 
 def GenerateRing(x,y, N): Generates square rings around a point in data which 
 has 300 columns(x) and 3000
 rows(y)
     indices = []
     for i in xrange(-N, N):
     indices.append((x+i, y-N))
     indices.append((x+N, y+i))
     indices.append((x-i, y+N))
     indices.append((x-N, y-i))
     return indices

No, this creates a one dimensional list with 2N elements of where each element 
is a two item tuple.


 
 
 def ComputeClasses(data):
     radius = .5
     points = []
     for cy in xrange(0, data.height):
     for cx in xrange(0, data.width):
 
     if data[cy,cx] == (0.0,0.0,0.0):
     continue
     else :
     centre = data[cy, cx]
     points.append(centre)
 
 
     change = True
 
     while change:
 
     for ring_number in xrange(1, 100):
     change = False
     new_indices = GenerateRing(cx, cy, ring_number)
     print new_indices
     for idx in new_indices:  
 I need help in this part as I am
 unable to device a method in which if the points are out of index,it should 
 stop and
     if idx[0] = 300 and idx[1] = 3000:   go to 
 next centre and start generating
 rings from there.. and again if the index is out of range .. this should 
 repeat
     continue
     else :
     point = data[idx[0], idx[1]]

You can use a few different methods. This is just one example.

for idx, temp_point in enumerate(new_indices):
try:
temp_point[0]
temp_point[1]
except Exception: #Should be IndexError I think.
print 'idx: {0}\ntemp_point:{1}'.format(idx, temp_point) 
# Possibly add a break or exit so you do not have to
# keep going once you hit a failure.
point = data[temp_point[0], temp_point[1]] 


What is `data`? I have not seen any built-in structure that takes
a tuple in this manner...unless it is a dictionary. Or from numpy.
Given my lack of knowledge of what `data`, it could be the
problem is there. That is one reason I accessed `temp_point[0]` and
`temp_point[1]` separately.


     if point == (0.0, 0.0, 0.0 ):
     print point
     continue
     else:
     dist = distance(centre, point)
     print dist
     if  dist  radius :   and rings 
 should be added only when this
 condition is satisfied
     print point
     points.append(point)
     change = True
     print change
 
 
     break
 
 
     print points
 
 
 ERROR now :
 
 data loaded
 [(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404), 
 (297, 405), (296, 404)] ... I am
 printing Indices to know what index it dies out..
 
 Traceback (most recent call last):
   File Z:/modules/Classify.py, line 73, in module
     ComputeClasses(data)
   File Z:/modules/Classify.py, line 49, in ComputeClasses
     point = data[idx[0], idx[1]]
 error: index is out of range
 

Is that the actual error? If so, then the problem is not `idx` or 
`temp_point` but instead `data`. If it is not the exact error, please 
copy and paste the error message *exactly* as given.

 [1][2]
IndexError: list index out of range
 (1,2)[3]
IndexError: tuple index out of range


~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: Problem with list.remove() method

2012-11-20 Thread Prasad, Ramit
Alvaro Combo wrote:
 
 Hi All,
 
 I'm relatively new to Python... but I have found something I cannot 
 explain... and  I'm sure you can help me.
 
 I have the following function that serves for removing the duplicates from a 
 list... It's a simple and (almost)
 trivial task.
 
 I'm using WingIDE as editor/debugger and have Python 2.7.3.
 
 When running this I have an error when trying to remove cpy_lst[4]... and 
 ONLY THAT!!! Even in interactive
 mode!!!
 
 Any suggestion is MOST welcome.
 
 Best Regards
 
 ACombo
 
 ...And the code:
 
 def remove_dup_5_10():
 
 Remove the duplicates of a given list. The original list MUST be kept.
 
 
 # Set the original list
 lst = ['a', 1, 10.0, 2, 'd', 'b', 'b', 'b', 1, 2, 'b' ]
 
 # NEED to create a copy... See dicussion on Problem 5.6 and issue #2
 cpy_lst = list(lst)
 
 # Perform an infinite loop... explained later
 i=0 # initialize the index
 while i != len(cpy_lst):
 if cpy_lst.count(cpy_lst[i]) != 1:
 cpy_lst.remove(i)
 else:
 i += 1
 
 print The original List: , lst
 print List with NO duplicates: , cpy_lst
 
 return True
 --

Remove looks for the *value* not the *index* of the value.

 help([].remove)
Help on built-in function remove:

remove(...)
L.remove(value) -- remove first occurrence of value.
Raises ValueError if the value is not present.

Change ` cpy_lst.remove(i)` to `cpy_lst.remove(cpy_lst[i])`.

~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: 10 sec poll - please reply!

2012-11-20 Thread Prasad, Ramit
Steven D'Aprano wrote:
 
 On Tue, 20 Nov 2012 07:18:42 -0800, Michael Herrmann wrote:
 
  Thanks again for your further replies. So far, it's 4 votes for
  'send_keys' and 1 vote for 'type'.
 
  Regarding 'send_keys': To me personally it makes sense to send keys _to_
  something. However, in our API, send_keys would not be called on an
  object or with a parameter indicating the target. It would just be
 
  send_keys(ENTER)
  send_keys(Hello World!)
  send_keys(CTRL + 'a')
 
 
 send_keys is wrong, because you aren't sending keys. You're sending
 strings, except you aren't actually sending strings either, because
 send does not make sense without a target. You're automating the typing
 of strings, including control characters.

simulate_keypress
simulate_key(s)_down
send_kb_press
fake_typing
send_char(s)

 
 I believe that your initial instinct for the name of this function was
 correct. It automates typing, so you should call it type or (for those
 paranoid about shadowing the built-in, type_str.
 

I can too easily see somebody doing from module import *  
OR from module import type.


~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: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
 
 Hello:
 
 I have a multihomed machine that I would like to run the Python imaplib's 
 IMAP4 client on.  I would like to be
 able to specify which interface the underlying socket will bind to as its 
 source address.  How could I best do
 this?

One assumes by programming.

 
 Thanks for any help...

You are quite welcome. :)

On a less flippant note, maybe some links would help you 
get started.

http://www.doughellmann.com/PyMOTW/imaplib/
http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ 
http://docs.python.org/2/library/imaplib.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: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
   I have a multihomed machine that I would like to run the Python imaplib's 
   IMAP4 client on.  I would like to be
   able to specify which interface the underlying socket will bind to as its 
   source address.  How could I best do
   this?
[snip]

 While I appreciate your attempt at humor, this is not information which helps 
 me.  Perhaps you are not familiar
 with the basics of socket programming. This is all fine and dandy, and it is 
 good to know what you don't know.
 If you're interested, look at the third argument to create_connection:
 http://docs.python.org/2/library/socket.html

Apologies, I misread your question. 

According to the imaplib docs, you can subclass IMAP4 and override 
`IMAP4.open` to create the socket and bind it to the desired interface.
You could also connect using IMAP4 and then close/reopen the socket
inside the IMAP4 connection object. 


I hope that is more help,
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: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
 
 On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote:
  brintoul at controlledthinking.com wrote:
 
  Apologies, I misread your question.
 
  According to the imaplib docs, you can subclass IMAP4 and override
  `IMAP4.open` to create the socket and bind it to the desired interface.
  You could also connect using IMAP4 and then close/reopen the socket
  inside the IMAP4 connection object.
 
  I hope that is more help,
  Ramit
 
 
 Thanks, yes, that helps!  Just out of curiosity, can you give me a quick link 
 to the docs you are looking at?
 I'm not seeing anything which gets very specific in the docs for Python 2.7 
 at docs.python.org ...


It is not very specific or helpful but here is the text in question.

'''
IMAP4.open(host, port)
Opens socket to port at host. This method is implicitly called by the IMAP4 
constructor. The connection objects established by this method will be used in 
the read, readline, send, and shutdown methods. You may override this method.
'''
http://docs.python.org/2.7/library/imaplib.html#imaplib.IMAP4.open


~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: xml data or other?

2012-11-19 Thread Prasad, Ramit
Artie Ziff wrote:
 
 On 11/9/12 5:50 AM, rusi wrote:
  On Nov 9, 5:54 pm, Artie Ziff artie.z...@gmail.com wrote:
  # submit correctedinput to etree
 I was very grateful to get the leg up on getting started down that
 right path with my coding. Many thanks to you, rusi. I took your
 excellent advices and have this working.
 
 class Converter():
  PREFIX = ?xml version=1.0?
  data
  
  POSTFIX = /data
  def __init__(self, data):
  self.data = data
  self.writeXML()
  def writeXML(self):
  pattern = re.compile('testname=(.*)')
  replaceStr = r'testname name=\1'
  xmlData = re.sub(pattern, replaceStr, self.data)
  self.dataXML = self.PREFIX + xmlData.replace(\\, /) +
 self.POSTFIX
 
 ###  main
 # input to script is directory:
 # sanitize trailing slash
 testPkgDir = sys.argv[1].rstrip('/')
 # Within each test package directory is doc/testcase
 tcDocDir = doc/testcases
 # set input dir, containing broken files
 tcTxtDir = os.path.join(testPkgDir, tcDocDir)
 # set output dir, to write proper XML files
 tcXmlDir = os.path.join(testPkgDir, tcDocDir + _XML)
 if not os.path.exists(tcXmlDir):
  os.makedirs(tcXmlDir)
 # iterate through files in input dir
 for filename in os.listdir(tcTxtDir):
  # set filepaths
  filepathTXT = os.path.join(tcTxtDir, filename)
  base = os.path.splitext(filename)[0]
  fileXML = base + .xml
  filepathXML = os.path.join(tcXmlDir, fileXML)
  # read broken file, convert to proper XML
  with open(filepathTXT) as f:
  c = Converter(f.read())
  xmlFO = open(filepathXML, 'w')   # xmlFileObject
  xmlFO.write(c.dataXML)
  xmlFO.close()
 
 ###
 
 Writing XML files so to see whats happening. My plan is to
 keep xml data in memory and parse with xml.etree.ElementTree.
 
 Unfortunately, xml parsing fails due to angle brackets inside
 description tags. In particular, xml.etree.ElementTree.parse()
 aborts on '' inside xml data such as the following:
 
 testname name=cron_test.sh
  description
  This testcase tests if crontab filename installs the cronjob
  and cron schedules the job correctly.
  \description
 
 ##
 
 What is right way to handle the extra angle brackets?
 Substitute on line-by-line basis, if that works?
 Or learn to write a simple stack-style parser, or
 recursive descent, it may be called?

I think your description text should be in a CDATA section.
http://en.wikipedia.org/wiki/CDATA#CDATA_sections_in_XML

~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 Interview Questions

2012-11-19 Thread Prasad, Ramit
Roy Smith wrote:
 
 OK, I've just read back over the whole thread.  I'm really struggling to
 understand what point you're trying to make.  I started out by saying:
 
  Use a list when you need an ordered collection which is mutable (i.e.
  can be altered after being created).  Use a tuple when you need an
  immutable list (such as for a dictionary key).
 
 To which you obviously objected.  So now you write:
 
  I think a tuple is an immutable sequence of items, and a list is a
  mutable sequence of items.
 
 So how is that different from what I said?  Is this whole argument
 boiling down to your use of immutable sequence vs. my use of
 immutable list?


'''
Roy:
 Use a list when you need an ordered collection which is mutable (i.e.
 can be altered after being created).  Use a tuple when you need an
 immutable list (such as for a dictionary key).
Steven:
I keep hearing about this last one, but I wonder... who *actually* does 
this? I've created many, many lists over the years -- lists of names, 
lists of phone numbers, lists of directory search paths, all sorts of 
things. I've never needed to use one as a dictionary key.
'''

To me this is more of a question than an argument. Now moving
on to your specific example.

'''
def extract_stack(lines):
in traceback_helper module 
header = lines[0]
stack = []
for line in lines:
m = frame_pattern.match(line)
if not m:
continue
frame = (m.group('path'), m.group('function'))
stack.append(frame)
# [Convert to tuple and return after finished building stack.]
return (header, stack)
[...]
def main(args):
crashes = {}
[...]
for line in open(log_file):
if does_not_look_like_a_stack_dump(line):
 continue
lines = traceback_helper.unfold(line)
header, stack = traceback_helper.extract_stack(lines)
signature = tuple(stack)
if signature in crashes:
count, header = crashes[signature]
crashes[signature] = (count + 1, header)
else:

crashes[signature] = (1, header)
'''

Seems to me that Steven is suggesting that stack (after being built)
should converted to a tuple before being returned, because a stack 
for any unique exception should be unique and immutable. You do this
anyway; you just do it before putting it into a dictionary rather
than before returning it.

Same net effect (as long as you do not modify `stack` later), so no 
real argument.


~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: Writing game-state data...

2012-11-09 Thread Prasad, Ramit
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

2012-11-09 Thread Prasad, Ramit
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, kwargs) 
duck(Foo).matches(IFoo, kwargs)

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: Python3.3 str() bug?

2012-11-09 Thread Prasad, Ramit
Chris Angelico wrote:
 
 What you really should be doing is not transforming the whole
 structure, but explicitly transforming each part inside it. I
 recommend you stop fighting the language and start thinking about your
 data as either *bytes* or *characters* and using the appropriate data
 types (bytes or str) everywhere. You'll then find that it makes
 perfect sense to explicitly translate (en/decode) from one to another,
 but it doesn't make sense to encode a list in UTF-8 or decode a
 dictionary from Latin-1.
 
[snip]
 
 You may be able to do some kind of recursive cast that, in one sweep
 of your data structure, encodes all str objects into bytes using a
 given encoding (or the reverse thereof). But I don't think this is the
 best way to do things.

I would think the best way is to convert as you load the data.
That way everything is in the correct format as you manipulate
and generate new data.

 
~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

2012-11-09 Thread Prasad, Ramit
Dennis Lee Bieber wrote:
 
 On Fri, 9 Nov 2012 17:07:09 +1100, Chris Angelico ros...@gmail.com
 declaimed the following in gmane.comp.python.general:
 
  On Fri, Nov 9, 2012 at 12:39 PM, Mark Lawrence breamore...@yahoo.co.uk 
  wrote:
   On 07/11/2012 01:55, Steven D'Aprano wrote:
  
  
   Who knows? Who cares? Nobody does:
  
   n -= n
  
  
   But I've seen this scattered through code:
  
   x := x - x - x
 
  Can you enlighten us as to how this is better than either:
   x := -x
  or
   x := 0 - x
 
   Of course, if one has a language that, for some reason, evaluates
 right-to-left (APL, anyone), then
 
   x := x - x - x
 
 becomes
 
   x := x - 0
 

Is that not the same as x:=-x?


~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: problem with module PyVisa

2012-11-09 Thread Prasad, Ramit
Jean Dubois wrote:
 
 On 9 nov, 17:40, Rodrick Brown rodrick.br...@gmail.com wrote:
  It seems pretty obvious from the error. Try installing the missing lib 
  packages.
 
  OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: cannot open shared
  object file: No such file or directory
 
  Sent from my iPhone
 
  On Nov 9, 2012, at 11:22 AM, Jean Dubois jeandubois...@gmail.com wrote:
 
   OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: cannot open shared
   object file: No such file or directory
 
 The error may be obvious but finding this file and how to install it
 is not unfortunately.
 It seems I have to install it from the National Instruments site but
 Debian Linux doesn't seem to be supported...
 and I doubt whether just copying this file will be sufficient to make
 PyVisa work.
 I wonder whether there might be another way to communicate via USB
 with a Keithley programmable power supply using Python.
 

Here are some reference links that might help.
http://stackoverflow.com/questions/8140248/linux-implementation-of-visa-api
https://decibel.ni.com/content/message/37590


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: How to print python commands automatically?

2012-11-09 Thread Prasad, Ramit
Peng Yu wrote:
 
  Is this what you want?
  http://docs.python.org/2/library/trace.html
 
 I'm not able to get the mixing of the python command screen output on
 stdout. Is there a combination of options for this purpose?
 
 ~/linux/test/python/man/library/trace$ cat main1.py
 #!/usr/bin/env python
 
 def f():
   print Hello World!
 
 f()
 ~/linux/test/python/man/library/trace$ cat main.sh
 #!/usr/bin/env bash
 
 python -m trace --count -C . main1.py -t
 
 ~/linux/test/python/man/library/trace$ ./main.sh
 Hello World!
 ~/linux/test/python/man/library/trace$ cat main1.cover
#!/usr/bin/env python
 
 1: def f():
 1:   print Hello World!
 
 1: f()
 

Try with just --trace?


C:\ramitpython.exe -m trace test.py
C:\ramit\Python27\lib\trace.py: must specify one of --trace, --count, --report, 
--listfuncs, or --trackcalls

C:\ramitpython -m trace --trace test.py
 --- modulename: test, funcname: module
test.py(2): def f():
test.py(5): f()
 --- modulename: test, funcname: f
test.py(3): print Hello World!
Hello World!
 --- modulename: trace, funcname: _unsettrace
trace.py(80): sys.settrace(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: Printing characters outside of the ASCII range

2012-11-09 Thread Prasad, Ramit
danielk wrote:
 
 The database I'm using stores information as a 3-dimensional array. The 
 delimiters between elements are
 chr(252), chr(253) and chr(254). So a record can look like this (example only 
 uses one of the delimiters for
 simplicity):
 
 name + chr(254) + address + chr(254) + city + chr(254) + st + chr(254) + zip
 
 The other delimiters can be embedded within each field. For example, if there 
 were multiple addresses for 'name'
 then the 'address' field would look like this:
 
 addr1 + chr(253) + addr2 + chr(253) + addr3 + etc ...
 
 I use Python to connect to the database using subprocess.Popen to run a 
 server process. Python requests
 'actions' like 'read' and 'write' to the server process, whereby the server 
 process performs the actions. Some
 actions require that the server send back information in the form of records 
 that contain those delimiters.
 
 I have __str__ and __repr__ methods in the classes but Python is choking on 
 those characters. Surely, I could
 convert those characters on the server before sending them to Python and that 
 is what I'm probably going to do,
 so guess I've answered my own question. On Python 2, it just printed the 
 'extended' ASCII representation.
 
 I guess the question I have is: How do you tell Python to use a specific 
 encoding for 'print' statements when I
 know there will be characters outside of the ASCII range of 0-127?

You just need to change the string to one that is not 
trying to use the ASCII codec when printing. 

print(chr(253).decode('latin1')) # change latin1 to your 
 # chosen encoding.
ý


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

2012-11-08 Thread Prasad, Ramit
wxjmfa...@gmail.com 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
 
  oscar.j.benja...@gmail.com 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: Multi-dimensional list initialization

2012-11-07 Thread Prasad, Ramit
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?

2012-11-07 Thread Prasad, Ramit
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 module
 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(encoding)` where encoding 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: Obnoxious postings from Google Groups

2012-11-06 Thread Prasad, Ramit
Grant Edwards wrote:
 On 2012-11-05, Roy Smith r...@panix.com wrote:
  In article mailman.3269.1352097585.27098.python-l...@python.org,
   Chris Angelico ros...@gmail.com 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

2012-11-06 Thread Prasad, Ramit
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 
'fooenterbar'enter 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

2012-11-06 Thread Prasad, Ramit
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

2012-11-06 Thread Prasad, Ramit
Dennis Lee Bieber wrote:
 
 On Tue, 06 Nov 2012 13:26:11 +0100, Peter Otten __pete...@web.de
 declaimed the following in gmane.comp.python.general:
 
  anuradha.raghupathy2...@gmail.com 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 rc:\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?

2012-11-06 Thread Prasad, Ramit
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

2012-11-06 Thread Prasad, Ramit
Steven D'Aprano wrote:
 
 On Tue, 06 Nov 2012 17:16:44 +, 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
  'fooenterbar'enter 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

2012-11-06 Thread Prasad, Ramit
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 stdin, line 1, in module
 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:
  snip
  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 multiplication doesn't make copies of *lists*, it's going
 nowhere fast, because people don't want the results that gives.
 
 So what difference 

RE: How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-06 Thread Prasad, Ramit
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: date and time comparison how to

2012-10-31 Thread Prasad, Ramit
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: how to change os.popen4 to subprocess

2012-10-30 Thread Prasad, Ramit
Replying to skyworld because I could not find the original message
from MRAB.

skyworld wrote:
 On Oct 27, 11:02 am, MRAB pyt...@mrabarnett.plus.com 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: better way for ' '.join(args) + '\n'?

2012-10-29 Thread Prasad, Ramit
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):
   rInput: 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', 'argument 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', 'argument 1', '$arg 2', even args containing a ' are ok)
 import pipes
 map(pipes.quote, a)
['program name', '\'argument 1\'', '$arg 2', '\'even args containing a 
\'\'\' are ok\'']
 ' '.join(a)
'\'program name\' \'argument 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: Appending a list using list obtained from a class

2012-10-25 Thread Prasad, Ramit
Demian Brecht wrote:
 On 2012-10-24, at 8:00 AM, inshu chauhan insidesh...@gmail.com 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?

2012-10-25 Thread Prasad, Ramit
andrea crotti wrote:
 2012/10/25 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:
  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

2012-10-25 Thread Prasad, Ramit
David Hutto wrote:
 On Wed, Oct 24, 2012 at 1:23 AM, seektime michael.j.kra...@gmail.com 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: regex function driving me nuts

2012-10-23 Thread Prasad, Ramit
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?

2012-10-23 Thread Prasad, Ramit
Nick Sabalausky wrote:
 On Mon, 22 Oct 2012 14:35:23 -0700 (PDT)
 darnold darnold992...@yahoo.com 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: A desperate lunge for on-topic-ness

2012-10-22 Thread Prasad, Ramit
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: Python does not take up available physical memory

2012-10-19 Thread Prasad, Ramit
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

2012-10-19 Thread Prasad, Ramit
Chris Angelico wrote:
 On Sat, Oct 20, 2012 at 4:08 AM, Pradipto Banerjee
 pradipto.baner...@adainvestments.com 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

2012-10-19 Thread Prasad, Ramit
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?

2012-10-19 Thread Prasad, Ramit
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

2012-10-19 Thread Prasad, Ramit
bbbenrothsch...@gmail.com 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

2012-10-18 Thread Prasad, Ramit
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

2012-10-18 Thread Prasad, Ramit
Chris Angelico wrote: 
 On Fri, Oct 19, 2012 at 3:13 AM, Neil Cerutti ne...@norwich.edu 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

2012-10-18 Thread Prasad, Ramit
David Hutto wrote:
 On Wed, Oct 17, 2012 at 7:12 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info 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

2012-10-18 Thread Prasad, Ramit
David Hutto wrote: 
 On Wed, Oct 17, 2012 at 12:38 PM, Prasad, Ramit
 ramit.pra...@jpmorgan.com wrote:
  David Hutto wrote:
  On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht demianbre...@gmail.com 
  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

2012-10-18 Thread Prasad, Ramit
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

2012-10-18 Thread Prasad, Ramit
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

2012-10-18 Thread Prasad, Ramit
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
 ramit.pra...@jpmorgan.com 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)

2012-10-18 Thread Prasad, Ramit
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: OT Questions

2012-10-17 Thread Prasad, Ramit
David Hutto wrote:
 On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht demianbre...@gmail.com 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: Aggressive language on python-list

2012-10-16 Thread Prasad, Ramit
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

2012-10-16 Thread Prasad, Ramit
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: Tkinter how to access the widget by name

2012-10-15 Thread Prasad, Ramit
 ? 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: for-loop on cmd-line

2012-10-11 Thread Prasad, Ramit
Chris Angelico wrote:
 On Fri, Oct 12, 2012 at 3:49 AM, Gisle Vanem gva...@broadpark.no wrote:
  wxjmfa...@gmail.com 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\Mpython -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: RE: Unpaking Tuple

2012-10-09 Thread Prasad, Ramit
Bob Martin wrote
 in 682592 20121008 232126 Prasad, Ramit ramit.pra...@jpmorgan.com 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: Insert item before each element of a list

2012-10-08 Thread Prasad, Ramit
Agon Hajdari wrote:
 Sent: Monday, October 08, 2012 3:12 PM
 To: python-list@python.org
 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

2012-10-08 Thread Prasad, Ramit
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

2012-10-08 Thread Prasad, Ramit
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: notmm is dead!

2012-10-05 Thread Prasad, Ramit
Steven D'Aprano wrote:
 Sent: Thursday, October 04, 2012 7:22 PM
 To: python-list@python.org
 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: Experimental Python-based shell

2012-10-04 Thread Prasad, Ramit
(A little quoting manipulation to make it easier to read with
appropriate context.)

  On Wed, Oct 3, 2012 at 11:25 AM, Amirouche Boubekki 
  amirouche.boube...@gmail.com wrote:
 
 2012/10/3 Jonathan Hayward jonathan.hayw...@pobox.com
   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


  1   2   3   >