Re: Call for a cooperation

2005-12-06 Thread Jeremiah
that seems to be very simple program.  You just ask the user for input
and save it to different lists.  What's the point, you could write that
program without knowing almost any python.  Just get a reference book
and you'll instantly have all the commands that you need.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonic exec* spawn*

2006-02-09 Thread Jeremiah
you can use the threads commands

-- 
http://mail.python.org/mailman/listinfo/python-list


python parser overridden by pymol

2009-11-11 Thread Jeremiah
Hello,

I'm fairly new to python (version 2.5.4), and am writing a program
which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from
debian.

It appears that when I add pymol to $PYTHONPATH, that parser.expr() is
no longer available, and so I am unable to use numpy.load(). I have
looked for where parser.expr() is defined in the python system so I
could place that directory first in $PYTHONPATH, but I have not been
able to find the file that defines expr().

My reason for using numpy.load() is that I have a numpy array which
takes an hour to generate. Therefore, I'd like to use numpy.save() so
I could generate the array one time, and then load it later as needed
with numpy.load().

I've successfully tested the use of numpy.save() and numpy.load() with
a small example when the pymol path is not defined in $PYTHONPATH  :

   >>> import numpy
   >>> numpy.save('123',numpy.array([1,2,3]))
   >>> numpy.load('123.npy')
   array([1, 2, 3])


However, a problem arises once $PYTHONPATH includes the pymol
directory. To use the pymol api, I add the following to ~/.bashrc:

   PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
   export PYMOL_PATH
   PYTHONPATH=$PYMOL_PATH
   export PYTHONPATH

Once this is done, numpy.load() no longer works correctly, as pymol
contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/
parser.py ), which apparently prevents python from using its native
parser.

   >>> numpy.load('123.npy')
   Traceback (most recent call last):
 File "", line 1, in 
 File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line
195, in load
   return format.read_array(fid)
 File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
line 353, in read_array
   shape, fortran_order, dtype = read_array_header_1_0(fp)
 File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
line 250, in read_array_header_1_0
   d = safe_eval(header)
 File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line
840, in safe_eval
   ast = compiler.parse(source, "eval")
 File "/usr/lib/python2.5/compiler/transformer.py", line 54, in
parse
   return Transformer().parseexpr(buf)
 File "/usr/lib/python2.5/compiler/transformer.py", line 133, in
parseexpr
   return self.transform(parser.expr(text))
   AttributeError: 'module' object has no attribute 'expr'

If I understand the problem correctly, can anyone tell me where
python.expr() is defined, or suggest a better method to fix this
problem?

Thanks,
Jeremiah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-25 Thread Jeremiah Dodds
rantingrickjohn...@gmail.com writes:

> On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote:
>> It has not. Python2 and Python3 are very similar. It's not like if
>> you learn Python using version 2, you have to relearn the language
>> when you want to switch Python3.  The syntax is the same, only
>> 'print' is a function instead of a statement.
>
> However, there is something to be said for "old habits die hard". I myself
> lament every time i must type->(, then blah, then->) AGAIN!. My fingers are
> hardwired for the old print statement. Damned that Guido and his mind games!
>
> http://www.youtube.com/watch?v=-Ny42Mdg5qo

I'm of the opinion that the solution to this involves configuring your editor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditional decoration

2012-06-18 Thread Jeremiah Dodds
r...@panix.com (Roy Smith) writes:

> Is there any way to conditionally apply a decorator to a function?
> For example, in django, I want to be able to control, via a run-time
> config flag, if a view gets decorated with @login_required().
>
> @login_required()
> def my_view(request):
> pass

You could write a decorator that takes the value of the flag and either
does nothing or decorates it's target function.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Jeremiah Yongue
It's definitely possible. I've done it myself.
On Jul 25, 2011 8:21 PM, "Robert"  wrote:
> Is it possible to install the 2 and 3 series side by side?
>
> --
> Robert
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constructive Criticism

2014-01-08 Thread jeremiah valerio
On Thursday, January 9, 2014 12:09:17 AM UTC-6, Ben Finney wrote:
> jeremiahvalerio...@gmail.com writes:
> 
> 
> 
> > Hi, hows it going I've been self teaching myself python
> 
> 
> 
> Welcome to Python, and to this discussion forum!
> 
> 
> 
> > and i typed up this small script now i know its not the best the
> 
> > coding is not the best but i would like to know of ways to make a
> 
> > small script like this better so all constructive critisim is Welcome.
> 
> 
> 
> Some constructive criticism:
> 
> 
> 
> * Please make an effort to write readable English here. A run-on
> 
>   sentence like the above makes it seem as though you don't care enough
> 
>   for our help to make your message easily readable.
> 
> 
> 
> * Please paste the code in your actual message, rather than directing to
> 
>   an ephemeral website. This is so that the discussion will always have
> 
>   the code for context when later readers view it.
> 
> 
> 
> Once you re-post your program and describe its purpose, I'm sure there
> 
> will be some responses giving feedback.
> 
> 
> 
> -- 
> 
>  \ “My girlfriend has a queen sized bed; I have a court jester |
> 
>   `\   sized bed. It's red and green and has bells on it, and the ends |
> 
> _o__) curl up.” —Steven Wright |
> 
> Ben Finney

yea sorry about this screw up "i know its not the best the coding is not the 
best but" and i'm new to forums never posted so i will take all your input and 
re-post maybe later thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Constructive Criticism

2014-01-09 Thread jeremiah valerio
On Thursday, January 9, 2014 3:56:37 AM UTC-6, Peter Otten wrote:
> jeremiahvalerio...@gmail.com wrote:
> 
> 
> 
> > Hi, hows it going I've been self teaching myself python, and i typed up
> 
> > this small script now i know its not the best the coding is not the best
> 
> > but i would like to know of ways to make a small script like this better
> 
> > so all constructive critisim is Welcome.
> 
> > 
> 
> > 
> 
> > 
> 
> > Here is the link to the code
> 
> > 
> 
> >" http://pastebin.com/5uCFR2pz "
> 
> 
> 
> > time.sleep(1)
> 
> > import time
> 
> > print("Closing in 9 ")
> 
> > time.sleep(1)
> 
> > import time
> 
> > print("Closing in 8 ")
> 
> 
> 
> - You should import modules just once, at the beginning of your script.
> 
> 
> 
> - Repetetive tasks are best handled with a for-loop, e. g.:
> 
> 
> 
> >>> import time
> 
> >>> for seconds_left in reversed(range(1, 10)):
> 
> ... print("Closing in", seconds_left, "seconds")
> 
> ... time.sleep(1)
> 
> ... 
> 
> Closing in 9 seconds
> 
> Closing in 8 seconds
> 
> Closing in 7 seconds
> 
> Closing in 6 seconds
> 
> Closing in 5 seconds
> 
> Closing in 4 seconds
> 
> Closing in 3 seconds
> 
> Closing in 2 seconds
> 
> Closing in 1 seconds
> 
> 
> 
> > user_input = input("\nWhos your favorite Football team? \n 1.Arizona
> 
> > Cardinals\n 2.Atlanta Falcons\n 3.Baltimore Ravens\n 4.Buffalo Bills\n
> 
> > 5.Miami Dolphins\n 6.Minnesota Vikings \n 7.New England Patriots \n
> 
> > 8.New Orleans Saints \n 9.Carolina 
> 
> [snip]
> 
> 
> 
> Python offers triple-quoted strings which may include newline literals:
> 
> 
> 
> user_input = input("""
> 
> Who's your favorite Football team?
> 
>  1. Arizona Cardinals
> 
>  2. Atlanta Falcons
> 
> ...
> 
> """)
> 
> 
> 
> > if user_input == "1" :
> 
> > print("\nThey suck! BYE!")
> 
> >  
> 
> > elif user_input == "2" :
> 
> > print("\nThey suck! BYE!")
> 
> >  
> 
> > elif user_input == "3" :
> 
> > print("\nThey suck!BYE!")
> 
> [snip]
> 
> 
> 
> Ignoring the typos you are taking the same action for all inputs but "17". 
> 
> So:
> 
> 
> 
> if user_input != "17":
> 
> print()
> 
> print("They suck! BYE!")
> 
> 
> 
> You should give some thought how unexpected user input like "", "123", 
> 
> "whatever" should be handled.
> 
> 
> 
> > elif user_input == "no" :
> 
> > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.")
> 
> > import time
> 
> > time.sleep(1)
> 
> > import time
> 
> > print("Closing in 9 ")
> 
> > time.sleep(1)
> 
> > import time
> 
> > print("Closing in 8 ")
> 
> > time.sleep(1)
> 
> > import time
> 
> 
> 
> OK, you are doing the count-down thing twice -- time to write a function, 
> 
> say countdown(), that you can put where you need a count-down instead of the 
> 
> repetetive code.

Thanks so much,exactly what i was looking for 
thanks for taking the time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Constructive Criticism

2014-01-09 Thread jeremiah valerio
On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn wrote:
> On 01/08/2014 11:56 PM, jeremiahvalerio...@gmail.com wrote:
> 
> > Hi, hows it going I've been self teaching myself python, and i typed up 
> > this small script now i know its not the best the coding is not the best 
> > but i would like to know of ways to make a small script like this better so 
> > all constructive critisim is Welcome.
> 
> >
> 
> >
> 
> >
> 
> > Here is the link to the code
> 
> >
> 
> > " http://pastebin.com/5uCFR2pz "
> 
> >
> 
> 
> 
> I'm not sure if someone already pointed this out, but imports only need
> 
> to be done once. Usually at the beginning of the file, but not always.
> 
> In your case I would say yes, at the beginning.
> 
> 
> 
> import sys
> 
> import time
> 
> 
> 
> def countdown(seconds):'
> 
>  # start at 'seconds' and count down with a for-loop
> 
>  for i in range(seconds, 0, -1):
> 
>  # print the current second (i)
> 
>  print('closing in {} seconds.'.format(i))
> 
>  # sleep for one second (no need to import time again).
> 
>  time.sleep(1)
> 
> 
> 
> # Example usage:
> 
> print('hello')
> 
> # Prints the countdown.
> 
> countdown(10)
> 
> sys.exit(0)
> 
> -- 
> 
> 
> 
> - Christopher Welborn 
> 
>http://welbornprod.com

Mr.Peter Otten did 

"- You should import modules just once, at the beginning of your script. "

   -Peter Otten
With his help this is what i have now

def countdown():
import time
for seconds_left in reversed(range(1, 10)):
print("Closing in", seconds_left, "seconds")
time.sleep(1)
exit()

if user_input == "yes" :
user_input = input("\nGreat what should we talk about?\nSports\nWeather")
elif user_input == "no" :
print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.")
countdown()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Constructive Criticism

2014-01-10 Thread jeremiah valerio
On Friday, January 10, 2014 2:56:14 AM UTC-6, Alister wrote:
> On Thu, 09 Jan 2014 13:05:23 -0800, jeremiah valerio wrote:
> 
> 
> 
> > On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn
> 
> > wrote:
> 
> >> On 01/08/2014 11:56 PM, jeremiahvalerio...@gmail.com wrote:
> 
> >> 
> 
> >> > Hi, hows it going I've been self teaching myself python, and i typed
> 
> >> > up this small script now i know its not the best the coding is not
> 
> >> > the best but i would like to know of ways to make a small script like
> 
> >> > this better so all constructive critisim is Welcome.
> 
> >> 
> 
> >> 
> 
> >> >
> 
> >> 
> 
> >> >
> 
> >> 
> 
> >> >
> 
> >> > Here is the link to the code
> 
> >> 
> 
> >> 
> 
> >> >
> 
> >> > " http://pastebin.com/5uCFR2pz "
> 
> >> 
> 
> >> 
> 
> >> >
> 
> >> 
> 
> >> 
> 
> >> I'm not sure if someone already pointed this out, but imports only need
> 
> >> 
> 
> >> to be done once. Usually at the beginning of the file, but not always.
> 
> >> 
> 
> >> In your case I would say yes, at the beginning.
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> import sys
> 
> >> 
> 
> >> import time
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> def countdown(seconds):'
> 
> >> 
> 
> >>  # start at 'seconds' and count down with a for-loop
> 
> >> 
> 
> >>  for i in range(seconds, 0, -1):
> 
> >> 
> 
> >>  # print the current second (i)
> 
> >> 
> 
> >>  print('closing in {} seconds.'.format(i))
> 
> >> 
> 
> >>  # sleep for one second (no need to import time again).
> 
> >> 
> 
> >>  time.sleep(1)
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> # Example usage:
> 
> >> 
> 
> >> print('hello')
> 
> >> 
> 
> >> # Prints the countdown.
> 
> >> 
> 
> >> countdown(10)
> 
> >> 
> 
> >> sys.exit(0)
> 
> >> 
> 
> >> --
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> - Christopher Welborn 
> 
> >> 
> 
> >>http://welbornprod.com
> 
> > 
> 
> > Mr.Peter Otten did
> 
> > 
> 
> > "- You should import modules just once, at the beginning of your script.
> 
> > "
> 
> > 
> 
> >-Peter Otten
> 
> > With his help this is what i have now
> 
> > 
> 
> > def countdown():
> 
> > import time for seconds_left in reversed(range(1, 10)):
> 
> > print("Closing in", seconds_left, "seconds")
> 
> > time.sleep(1)
> 
> > exit()
> 
> > 
> 
> > if user_input == "yes" :
> 
> > user_input = input("\nGreat what should we talk
> 
> > about?\nSports\nWeather")
> 
> > elif user_input == "no" :
> 
> > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.")
> 
> > countdown()
> 
> 
> 
> you could improve your countdown function further by adding an optional 
> 
> count vaule
> 
> 
> 
> def countdown(count=10):
> 
> for timeleft in reversed(1,count):
> 
> print ("Shutting down in {} Seconds".format(timeleft))
> 
> time.sleep(1)
> 
> -- 
> 
> Most people can't understand how others can blow their noses differently
> 
> than they do.
> 
>   -- Turgenev

So always think of the if's and possibility's that 
other people might do, thanks for you input. 
-- 
https://mail.python.org/mailman/listinfo/python-list


compiling matplotlib in virtual env

2015-10-01 Thread Rolston Jeremiah
Hello everyone,

I been trying to compile matplotlib in a python3.4 virtual env using 
pip version 1.7 on Fedora 22. I am in about 3 weeks learning python 
and Django so I am not clear on the error response to:


commmand
=

pip3 install matplotlib


error message
=


Traceback (most recent call last):
  File "", line 20, in 
  File "/tmp/pip-build-b_yuukm4/matplotlib/setup.py", line 155, in 
result = package.check()
  File "/tmp/pip-build-b_yuukm4/matplotlib/setupext.py", line 961, in check
min_version='2.3', version=version)
  File "/tmp/pip-build-b_yuukm4/matplotlib/setupext.py", line 445, in 
_check_for_pkg_config
if (not is_min_version(version, min_version)):
  File "/tmp/pip-build-b_yuukm4/matplotlib/setupext.py", line 173, in 
is_min_version
return found_version >= expected_version
  File "/usr/lib64/python3.4/distutils/version.py", line 76, in __ge__
c = self._cmp(other)
  File "/usr/lib64/python3.4/distutils/version.py", line 343, in _cmp
if self.version < other.version:
TypeError: unorderable types: str() < int()


Command "python setup.py egg_info" failed with error code 1 in 
/tmp/pip-build-b_yuukm4/matplotlib


Appreciate  your help
thanks

rjae



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How many followers of comp.lang.python

2009-01-28 Thread Jeremiah Dodds
On Tue, Jan 27, 2009 at 10:07 AM, rantingrick  wrote:

> I curious of how many are "really" out there. I have been watching the
> list for some time but basically see the same 10 or so people
> answering questions.
>
> Reply to this message so we can see how many exists here
>
> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm sure there are a lot more people lurking than actually posting.

I personally do a lot more lurking than posting - plus I post through google
groups at the moment, which means that at least some of the regular posters
won't see what I post.

I've learned an awful lot by lurking the mailing lists, hopefully I'll be
able to contribute more in the future.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: how to get all repeated group with regular expression

2008-11-22 Thread Jeremiah Dodds
On Fri, Nov 21, 2008 at 9:12 PM, scsoce <[EMAIL PROTECTED]> wrote:

> MRAB wrote:
>
>> Steve Holden
>> wrote:
>>
>>> Please keep this on the list.
>>>
>>> scsoce wrote:
>>>
 Steve Holden wrote:

> scsoce wrote:
>
>
>> say, when I try to search and match every char  from variable length
>> string, such as string '123456',  i tried re.findall( r'(\d)*, '12346'
>> )
>>
>>
> I think you will find you missed a quote out there. Always better to
> copy and paste ...
>
>
>
>> , but only get '6' and Python doc indeed say: "If a group is contained
>> in a part of the pattern that matched multiple times, the last match
>> is
>> returned."
>>
>>
> So use
>
>r'(\d*)'
>
> instead and then the group includes all the digits you match.
>
>
>
>> cause the regx engine cannot remember all the past history then ?  is
>> it
>> nature to all regx engine or only to Python ?
>>
>>
> Different regex engines have different capabilities, so I can't speak
> to
> them all. If you wanted *all* the matches of *all* groups, how would
> you
> have them returned? As a list? That would make the case where there was
> only one match  much tricker to handle. And what would you do with
>
>  r'((\w)*\d)*)'
>
> Also, what about named groups? I can see enough potential
> implementation
> issues that I can perfectly understand why Python works the way it
> does,
> so I'd be interested to know why it doesn't makes sense to you, and
> what
> you would prefer it to do.
>
> regards
>  Steve
>
>
 maybe my expression was not clear. I  want to capture every matched part
 in a repeated pattern, not only the last,  say, for string '123456',  I
 want to back reference any one char, not only the '6'. and i know the
 example is very simple, so we can got the whole string using regx and
 get every char using other python statements, but if the pattern in
 group is complex?
 and I test in VIM, it can do the 'back reference':
 ==you text in vim:
 123456
 == pattern:
 :%s/\(\d\)*/$2
 text will turn to be:
 2

  'Fraid the Python re implementers just decided not to do it that way.
>>>
>>>  Nor Perl.
>>
>> Probably what you want is re.findall(r"(\d)", "123456"), which returns a
>> list of what it captured.
>>
>>
>> 
>>
> Yes, you are right, but this way findall() capture only the 'top' group.
> What I really need to do is to capture nested and repated patterns, say,
>  tag in html contains many ,contains many ,   the
>  data in   is i need, so I write the regx like this:
>   regx ='''
>   (
>  (\s*   (\s*\n|\n)*
>   \s*\n
>  |\n)*
>  )
>  \s*
>   '''
> Steve Holden wrote:
>
>> I can see enough potential implementation
>> issues that I can perfectly understand why Python works the way it does,
>> so I'd be interested to know why it doesn't makes sense to you, and what
>> you would prefer it to do.
>>
>>
>
> As Steve said, if re really cannot do this kind of work , so I have to
> split the one line regx down, and  capture  first, and then loop to
> catpure , and then , and so on ... . I donnot like this way compared
> with the above one clean regx line.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you're parsing structured markup like HTML, why not use something meant
for that? I personally find BeautifulSoup (
http://www.crummy.com/software/BeautifulSoup/) to be very good at this. For
instance, here's a code snippet I recently used to pull out specific data
from a table in a site:

soup = BeautifulSoup(some_page)
opts = [fonttag.string.strip()
   for row in soup('tr', attrs={'class':'targetClass'})
   for cell in row('td')
   for fonttag in cell('font')
   if cell('font')]
--
http://mail.python.org/mailman/listinfo/python-list


Re: build minimal python 2.6 on linux

2008-11-23 Thread Jeremiah Dodds
On Sat, Nov 22, 2008 at 9:31 PM, r <[EMAIL PROTECTED]> wrote:

>
>
> And i know this may be asking alot but:
> where do i put the files before i run "./configure"
> does it matter what directory there in??
> any help here would be great since i am new to linux
> and have never built a python installation.
> Gracias amigos!
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


It doesn't matter where you put the source, but you should probably put it
somewhere under your home directory.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emacs vs. Eclipse vs. Vim

2008-11-30 Thread Jeremiah Dodds
There is, as other people have pointed out, no "correct" answer to this
question, other that "use a few different editors, and settle on what you
like".

I personally use emacs. In fact, I use emacs for a lot more than just
editing code.

The reason I found myself really liking emacs was because I'm the type of
person who likes to be able to really customize whatever I'm using to my
tastes - emacs is _meant_ to be customized, and although the learning curve
is steep (especially if you have no previous exposure to lisps), it is
possible to be tearing emacs apart to fit your tastes within a few weeks to
a month of using it.

If you're the same type of person, you'll probably enjoy emacs.

I do advocate learning a powerful text editor, because the reward for
spending a lot of time learning one is very great. The only editors I'm
aware of that stand out from the crowd as being more powerful than the mass
of other editors are emacs and vim - but then again, I don't have much
experience with newer editors (for instance, Eclipse is a lot more
extensible than I previously thought that it was).

A word of warning is in order though - if you _do_ decide to spend the time
learning a powerful text editor off the bat in your journey as a programmer,
prepare to be _extremely_ frustrated for a while. It may be more prudent to
stick with editors that have an interface that you're used to (but support
syntax highlighting, auto-indentation, etc) than to jump into the unknown. A
little bit of programming experience can make understanding editors like vim
and emacs a lot easier than otherwise.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pycon 2009

2008-11-30 Thread Jeremiah Dodds
On Sat, Nov 29, 2008 at 1:59 AM, r <[EMAIL PROTECTED]> wrote:

> do you have any suggestions where? I am not as versed as you in Usenet.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Try comp.lang.lisp
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyhon (with wxPython) on Windows' cygwin: can it be done fully ?

2008-12-02 Thread Jeremiah Dodds
On Mon, Dec 1, 2008 at 12:25 PM, Fernando H. Sanches <
[EMAIL PROTECTED]> wrote:

> At first I also disliked print's new syntax, but later I realised it
> could be useful.
>
> However, I agree that the parentheses are annoying. Not because of the
> parens theirselves, but because of the Shift key.
>
> Why programmers stilll can't have special keyboards with parens keys
> that doesn't need pressing "shift"? Isn't time C programmers have  a
> "&" key and perl programmers a $ one? And why the heck we need shift
> for "(" and not for "[" or "{", since the first one is much more used
> (even outside programming)?
>
> Really, we don't need to change our syntax, we need to change our
> keyboards. We are so blinded by tradition that we are losing
> productivity.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Obligatory:
http://groups.google.com/group/comp.lang.lisp/msg/f499cca6b478260f?hl=en&pli=1

I've actually always wanted to try doing something like that, but haven't
actually worked up the gumption to go anywhere past swapping caps and ctrl.
--
http://mail.python.org/mailman/listinfo/python-list


Re: noob needs help

2008-12-03 Thread Jeremiah Dodds
On Wed, Dec 3, 2008 at 1:01 AM, Sambo <[EMAIL PROTECTED]> wrote:

> Peter Pearson wrote:
>
>
> In slackware one needs "./" before the filename if you executing
> files in current dir.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Umm, only if you're running files marked as executable. If you're running
foo.py file by typing "python foo.py", you shouldn't need to type "python
./foo.py" .

Besides, wouldn't that be an issue with whatever shell you were using
anyhow, and not an issue with slackware?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple equates

2008-12-03 Thread Jeremiah Dodds
On Wed, Dec 3, 2008 at 6:23 AM, Lawrence D'Oliveiro
<[EMAIL PROTECTED]> wrote:

>
> So why is that better?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I personally think that it looks marginally cleaner (indentation issues
aside).

Do you think it's substantially worse? If so, why?

I mean you asked how you would express the original code with the lambda -
that's how you would, by pulling the lambda out into a function. How would
you express it better is a different question.

I think that the code in question is an example of a case where a lambda is
appropriate in python, but it's definitely not any worse for having the code
pulled out. If the function wasn't trival, you'd have to anyhow.

The whole "lambdas good or bad" thing has been done to death as far as it
relates to python. For python, it seems that anonymous functions are a no-no
unless they're effectively one liners.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a .xls file to .html

2008-12-03 Thread Jeremiah Dodds
On Wed, Dec 3, 2008 at 5:54 AM, tarun <[EMAIL PROTECTED]> wrote:

> Hello All,
>
> I've a .xml file (saved as .xls) that can be opened in Microsoft excel. I
> want to write python code that converts this excel file into .html (so that
> it can be viewed as is in an explorer).
>
> Can any one help?
>
> Regards,
> Tarun
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
A quick google search shows http://pyxlreader.sourceforge.net/ , and a few
other libraries for reading xls files. I don't use excel, so I can't test
it. There may not be a library for going straight from xls -> html, but if
you can get xls -> text  or a list or whatnot, then you could use pretty
much any html generation tool you want on it, python's got plenty of
templating libraries available.
--
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 3.0 final

2008-12-03 Thread Jeremiah Dodds
thankers.append(self)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple equates

2008-12-04 Thread Jeremiah Dodds
On Thu, Dec 4, 2008 at 1:19 PM, Hendrik van Rooyen <[EMAIL PROTECTED]>wrote:

>
>  "Cameron Laird" <[EMAIL PROTECTED]> wrote:
>
> > There's a realm within Pythonia that favors lambdalessness.
>
> And who, may I ask, Is the King of this realm?
>
> - Hendrik
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Guido?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python advocacy ... HELP!

2008-12-04 Thread Jeremiah Dodds
On Thu, Dec 4, 2008 at 1:52 AM, Michael_D_G <[EMAIL PROTECTED]> wrote:

>
> I am a faculty member of a cs department. We currently teach C++ in
> our intro to programming course. I am teaching this class and it seems
> to me that we would be much better served teaching python in the intro
> course, C++ for Data structures, as we do now, and Java in object
> oriented programming, as we do now.
> Some of my colleagues agree with me but some still see python as a
> niche language and don't understand
> how we could teach anything beyond C, C++ or Java.
>
> I have looked at several interesting academic papers, on doing just
> this approach. I have also looked through the
> python web page to get examples of industry players using python in a
> non-trivial way. Yes, I know, Google,
> Microsoft, Sun, CIA website running on Plone, NOAA, NASA. If anyone
> has any recent articles,
> or if anyone on the list is at a fortune 500 company, how do I refute
> the notion that Python
> is a "marginal" language because according to TOBIE it only less than
> a  6% market share.
>
> -michael
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Well, I'm not in a fortune 500, but python _is_ currently paying my bills.
There is a python job board, and a very active community around the language
- I don't think it's hard to show that it's not a "niche" language anymore.
Canonical,  as well as Google, O'reilly, Sun,  _and_ Microsoft  are
sponsors of the PSF. That's pretty much every major name in the
software-development world right now. Niche languages aren't going to be
getting that much support, from that many sources. Blender uses python.
Bittorrent. Trac. Bazaar. Mercurial. But you know all this already.

It seems to me that it shouldn't even matter if it _is_ a niche language
though, considering that you're trying to convince people to use it as an
"intro to programming" language. I would think that an introductory
programming course in this day and age should be more about general concepts
than language bits, and python is pretty good at staying out of your way -
other than Scheme, I can't think of a better language to use to demonstrate
the process of programming on a high level. Showing some code to your
colleagues, in both C++ and python, and showing how the python code is close
to being psuedo-code, and easier to understand would help, as well as
showing the interpreter (or ipython), and how that could be very useful in
class.

It's intro to programming - the specific language should take a backseat to
how easy it is to express ideas to the person with no programming experience
in a clean manner, right? It seems to me that that's the point that your
colleagues need to understand - being a good programmer (and, by
association, being led down the path to being a good programmer) is more
about understanding abstraction and how to break down a problem than what
language is used, especially at the beginning. This was perhaps less true 10
years ago, when it was much more important to have a firm understanding of
what's going on at a lower level to implement anything non-trivial, but
these days there are plenty of useful things and learning that can be done
with practically no knowledge of (for instance) machine architecture.

I know the above wasn't exactly what you were asking for, but I hope it
wasn't useless.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guido's new method definition idea

2008-12-06 Thread Jeremiah Dodds
On Fri, Dec 5, 2008 at 9:21 PM, Daniel Fetchinson <[EMAIL PROTECTED]
> wrote:

>
> The proposal is to allow this:
>
> class C:
>def self.method( arg ):
>self.value = arg
>return self.value
>
> instead of this:
>
> class C:
>def method( self, arg ):
>self.value = arg
>return self.value
>
> I.e. explicit self stays only the syntax is slightly different and may
> seem attractive to some. As pointed out by Guido classmethods would
> work similarly:
>
> class C:
>@classmethod
>def cls.method( arg ):
>cls.val = arg
>return cls.val
>
>
-1. It doesn't solve a real problem, just shuffles syntax around with very
little, if any, gain in clarity.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is slow

2008-12-10 Thread Jeremiah Dodds
Does anybody else think it's really funny when people argue over which
language used for _web apps_ is fastest? I mean, I'm not aware of any
language that's slow enough to make it noticeable compared to say, network
latency or database access. I guess you might notice if you're not caching
any content, and your language of choice is _really_ bad at generating
strings in a for loop.

As far as "slow" goes, the clear winner(?) is Ruby, and there are _plenty_
of sites written in ruby that aren't slow. The ones that are slow aren't
slow because of ruby  - they're slow primarily because of people not knowing
how to write a database schema, as far as I can tell.

There seems to be a lot of stigma against python as being a "slow" language,
which I suppose it is when measured in certain ways - however it's more than
fast enough for me, and is certainly fast enough for web-apps (I run a few
sites on top of CherryPy, and have _never_ had an issue with them, even with
a minor redditing on one of them).

I had a freelance gig once porting an image-manipulation algorithm from C++
to python. It was a horrible mess of C++ code, but ran very fast (and did
exactly what my employer needed it to do). Porting it to python in a literal
led to (IIRC) a 10x speed-down. Changing that to more idiomatic python made
it only 3-5x slower than the C++. After translating that into, I think,
PyRex, it was barely slower than the original code. Certainly well within
the "acceptable" range.

When I did the above, I was really pretty new to python. If I did the same
job again, I'd probably get better results, just from understanding the
language better. But I digress.

The only places that I'm aware of where performance would be enough of an
issue to make Python a poor choice are places where using python would
_never_ be considered anyhow.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error with SOAPpy

2008-12-13 Thread Jeremiah Dodds
On Sat, Dec 13, 2008 at 10:54 PM, Amit Goyal  wrote:

> Hi All,
>
> I am new to Python and was trying the sample code on Dive into Python
> for WSDL. Below is the error I get.
>
> Traceback (most recent call last):
>  File "", line 4, in -toplevel-
>print 'Light sensor value: ' + server._ns(namespace).readLSpercent
> (int_1 = "1")
>  File "c:\Python24\Lib\site-packages\SOAPpy\Client.py", line 470, in
> __call__
>return self.__r_call(*args, **kw)
>  File "c:\Python24\Lib\site-packages\SOAPpy\Client.py", line 492, in
> __r_call
>self.__hd, self.__ma)
>  File "c:\Python24\Lib\site-packages\SOAPpy\Client.py", line 363, in
> __call
>config = self.config)
>  File "c:\Python24\Lib\site-packages\SOAPpy\Client.py", line 187, in
> call
>r.endheaders()
>  File "c:\Python24\lib\httplib.py", line 798, in endheaders
>self._send_output()
>  File "c:\Python24\lib\httplib.py", line 679, in _send_output
>self.send(msg)
>  File "c:\Python24\lib\httplib.py", line 646, in send
>self.connect()
>  File "c:\Python24\lib\httplib.py", line 614, in connect
>socket.SOCK_STREAM):
> gaierror: (11001, 'getaddrinfo failed')
>
> I am using Python 2.4.4 and the following versions.
>
> >>> xml.__version__
> '0.8.4'
> >>> fpconst.__version__
> '0.7.2'
> >>> SOAPpy.__version__
> '0.12.0'
>
> Regards,
> Amit
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Are you behind a proxy?
--
http://mail.python.org/mailman/listinfo/python-list


Re: New Python 3.0 string formatting - really necessary?

2008-12-20 Thread Jeremiah Dodds
On Sat, Dec 20, 2008 at 12:30 AM, r  wrote:

> Why could't we improve on what we had instead of
> making radical changes? Thats all i am asking.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Often times improving on what you have involves radical changes, especially
if the goals of what you have change, or were not fully understood during
their original implementation.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beep

2008-12-23 Thread Jeremiah Dodds
On Mon, Dec 22, 2008 at 10:42 PM, Jeffrey Barish
wrote:

>
>
> On Ubuntu, it is possible to set visual and audible beeps separately.  When
> I set both, I get the visual beep, but not the audible one.  It's not a
> Python issue -- so I should take this thread to Ubuntu -- because I observe
> this behavior even when I hit backspace at the beginning of a line in a
> terminal.
> --
> Jeffrey Barish
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Well, I would try printing a bell character in another language, say ruby or
perl, or just in the terminals on the machines that won't print them in
python. If you get a bell from those, it's likely some issue with your
python installation, otherwise it's likely a problem with Ubuntu
configuration somewhere.
--
http://mail.python.org/mailman/listinfo/python-list


Re: object oriënted

2008-12-25 Thread Jeremiah Dodds
On Wed, Dec 24, 2008 at 10:54 AM, Dennis van Oosterhout <
de.slotenzwem...@gmail.com> wrote:

> I know that python is an Object Oriënted language but I was wondering if it
> gets used as a non-OOP also (by a good amount of people).
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
I, for one, use the different "paradigms" (OO, procedural, functional, etc)
where they feel appropriate for solving different problems.

I have quite a few strictly procedural scripts, mainly for sysadmin stuff
and generating project skeletons.

Most of the "complete" programs that I write use a mix of OO and functional
paradigms.
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system('cls')

2008-12-25 Thread Jeremiah Dodds
On Thu, Dec 25, 2008 at 7:11 AM, Dennis van Oosterhout <
de.slotenzwem...@gmail.com> wrote:

> Btw...does that mean that system('cls') only works on Windows...or to
> say it otherwise: the program isn't platform independant?
>
>
Yes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function to remove escape characters from a string ?

2008-12-25 Thread Jeremiah Dodds
On Thu, Dec 25, 2008 at 7:02 AM, James Stroud  wrote:

> Stef Mientki wrote:
>
>> hello,
>>
>> Is there a function to remove escape characters from a string ?
>> (preferable all escape characters except "\n").
>>
>> thanks,
>> Stef
>>
>
>
>
import string

test = 'this\r is a test\t yeah\n'

for c in string.printable[-5:]:
 if c != '\n':
test = test.replace(c, ' ')


Hmm, should the escape codes be in their own little list in string? Or are
they, and I'm just not seeing them? Is string.printable[-5:] a reliable way
to get the list of escape codes?
--
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite install error on hp ux (ld: Can't find library for -lpython2.5)

2008-11-09 Thread Jeremiah Dodds
On Sun, Nov 9, 2008 at 9:29 PM, Geon. <[EMAIL PROTECTED]> wrote:

> hi everyone!
>
> when i install pysqlite i meet bellow error. ( use easy_install and
> source code building same problem )
>
> ld: Can't find library for -lpython2.5
>
> what mean this message? and what i do?
>
> my system is hp-ux 11i v3. and python2.5 is installed.
> ld command also avaliable.
>
> please help for me~
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I don't know much about hp-ux, but assuming they have a package manager that
you installed python from, you might need to install the python development
package.
--
http://mail.python.org/mailman/listinfo/python-list


Re: First post, recursive references with pickle.

2008-11-10 Thread Jeremiah Dodds
On Mon, Nov 10, 2008 at 4:36 PM, George Sakkis <[EMAIL PROTECTED]>wrote:

> On Nov 10, 2:23 pm, mark starnes <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone, this is my first post to this group, so please be gentle.
> >
> > I've written a class which, when I attempt to pickle, gives the error:
> >
> > *** RuntimeError: maximum recursion depth exceeded
> >
> > Is there a way to make pickle display data about what it's trying
> > to do?  I'm thinking that if so, the recursive component will be
> > immediately visible, easing the bug hunt.
> >
>

Your class doesn't happen to include BeautifulSoup objects, does it?

Or:

" Trying to pickle a highly recursive data structure may exceed the maximum
recursion depth, a RuntimeError will be raised in this case. You can
carefully raise this limit with sys.setrecursionlimit()."

>From http://docs.python.org/library/pickle.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Project layout / Import files from different subdirectories

2008-11-11 Thread Jeremiah Dodds
On Tue, Nov 11, 2008 at 7:08 AM, Markus Mayer <[EMAIL PROTECTED]> wrote:

> Steve Holden schrieb:
> > If you want shorter names in your main code, of course, you can use
> >
> > import project.main as main
> > import project.gui.mainwindow as window
> >
> > or somethihg similar.
> >
> > regards
> >  Steve
>
>

Are explicit relative imports applicable here? Could he do a

from .. import project.main as main

without adding another __init__.py?

Or do I have my head screwed on funny?
--
http://mail.python.org/mailman/listinfo/python-list


Re: SHA1withRSA in python

2008-11-11 Thread Jeremiah Dodds
On Tue, Nov 11, 2008 at 12:40 PM, Mailing List SVR
<[EMAIL PROTECTED]>wrote:

> Hi all,
>
> in java there are several libraries for sha1withrsa, there is something
> similar in python?
>
> thanks
> Nicola
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


http://docs.python.org/library/crypto.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Jeremiah Dodds
On Tue, Nov 11, 2008 at 6:29 PM, Phillip B Oldham
<[EMAIL PROTECTED]>wrote:

>
> anyone with an openid account to register with our webapps, we simply
> want to centralise registration and sign-on for our employees.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Are your webapps written in python or something else? If they're written in
python, it doesn't seem like it would be very hard to set up automation of
registration / sign on for all the apps from one spot. As far as I can tell,
it would be trivial to do with (for instance) CherryPy.

If they're not, then why the requirement of a python SSO server?
--
http://mail.python.org/mailman/listinfo/python-list


Re: The return code

2008-11-13 Thread Jeremiah Dodds
On Thu, Nov 13, 2008 at 7:15 AM, devi thapa <[EMAIL PROTECTED]> wrote:

> Hi,
>
>  I am running one service in the python script eg like
> "service httpd status".
> If I execute this command in normal shell kernel, the return code is
> 3. But in the python script its return code is different, ie not 3, I
> mean to say that return codes are differing.
> But I want the return code  3 , not the other one. So, how can I achieve
> this?
>
> Regards,
> Devi.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Well, I would perhaps start by finding out what the return codes mean. And
then I would move on to figuring out why they would be different in the
script, and then making the appropriate changes. It's probably a difference
in how the "service" is called, or the environment it's called in.
--
http://mail.python.org/mailman/listinfo/python-list


Re: special editor support for indentation needed.

2008-11-16 Thread Jeremiah Dodds
On Mon, Nov 17, 2008 at 1:36 AM, John Yeung <[EMAIL PROTECTED]>wrote:

> On Nov 15, 8:50 pm, "Eric S. Johansson" <[EMAIL PROTECTED]> wrote:
> > well, therein lies the rub.  I don't know lisp,
> > I don't know Emacs internals let alone python mode.
>
> Is vr-mode a "major" mode?  If so, I suppose it can't be active at the
> same time as python-mode, which is also a major mode.
>
>

I'm not familiar with vr-mode, but a quick glance at at vr.el on sourceforge
shows it to be a minor mode. There are a few ways of combining major modes
as well (two-mode-mode, mmm-mode, mumamo).

Eric, I don't have a good readily available solution to what you're trying
to do, but it seems to me that it would be worth your time to get
comfortable with elisp, and how it's used in emacs. The emacs documentation
is pretty good, even if you don't know lisp, and I think it would be one of
the easiest languages to integrate well with voice recognition. I don't
think you would need to touch what is commonly referred to as emacs
internals to do what you want. There's a good chance that you'd be able to
greatly improve emacs voice-recognition support pretty easily in a month or
twos time.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-18 Thread Jeremiah Dodds
On Tue, Nov 18, 2008 at 7:39 PM, <[EMAIL PROTECTED]> wrote:

> Hi guys,
>
> I'm learning Python by teaching myself, and after going through several
> tutorials I feel like I've learned the basics. Since I'm not taking a class
> or anything, I've been doing challenges/programs to reinforce the material
> and improve my skills. I started out with stuff like "Guess my number"
> games, hangman, etc. and moved on to making poker and card games to work
> with classes. For GUIs I created games like minesweeper, and a GUI stock
> portfolio tracker. I am out of ideas and am looking for programming
> projects, challenges, or programs that have helped you'll learn. I'm working
> on the project Euler problems, but I find that they don't really help my
> programming skills; they are more math focused. Suggestions? What has been
> useful or interesting to you? I'd also welcome sources of textbook type
> problems, because the ones provided in tutorials tend to be repetitive.
>
> Thanks,
> Ben
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Try implementing a tetris clone. I find it to be a good exercise while
learning a new language. Also, the "Programming python" book has a text
editor example in it that is fun to extend / modify. Project Euler is good
to go through, and will improve your programming skills, but in a different
direction than other programming exercises can.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in Tkinter for Python 2.6

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 4:57 AM, Eric Brunel <[EMAIL PROTECTED]> wrote:

> Hello all,
>
> I'm trying out Python 2.6 and I found what might be a bug in the Tkinter
> module. How can I report it?
>
> The possible bug is a traceback when trying to delete a menu item in a menu
> where no items have associated commands.
>
> For example:
> --
> from Tkinter import *
>
> root = Tk()
>
> mb = Menu(root)
> root.configure(menu=mb)
>
> fm = Menu(mb)
> mb.add_cascade(label='File', menu=fm)
>
> fm.add_command(label='Open')
> fm.add_command(label='Quit')
>
> def remove_menu_item():
>  fm.delete(1)
>
> Button(root, text='Remove menu item',
> command=remove_menu_item).pack(padx=12, pady=24)
>
> root.mainloop()
> --
>
> Clicking on the button should remove the 'Open' item in the 'File' menu,
> but ends up in a traceback:
>  File "/opt/Python2.6+Tk8.5/bin/Linux/lib/python2.6/lib-tk/Tkinter.py",
> line 1410, in __call__
>return self.func(*args)
>  File "menu.py", line 15, in remove_menu_item
>fm.delete(1)
>  File "/opt/Python2.6+Tk8.5/bin/Linux/lib/python2.6/lib-tk/Tkinter.py",
> line 2670, in delete
>if c in self._tclCommands:
>
> It just seems the _tclCommands attribute on menus is initialized to None
> and never changed if none of the items actually have a command.
>
> Thanks!
> --
> python -c "print ''.join([chr(154 - ord(c)) for c in
> 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I can confirm this behavior in 2.6: Full traceback (as Eric's is missing the
last line)

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
  File "", line 2, in remove_menu_item
  File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 2670, in delete
if c in self._tclCommands:
TypeError: argument of type 'NoneType' is not iterable


The example code works "as expected" under 2.5.

I don't know enough about Tkinter to know whether or not this is actually a
bug, or intended behavior, but it certainly strikes me as being a bug.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 7:12 AM, Mr. SpOOn <[EMAIL PROTECTED]> wrote:

> On Wed, Nov 19, 2008 at 2:39 AM, Mensanator <[EMAIL PROTECTED]> wrote:
>
>  What
> requisites should have the host to run python code?
>
> Thanks and sorry for the meddling.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If the host is linux-based (possibly if not, I don't have much experience
otherwise, so I can't say), and allows ssh access, you should be able to
write and run python code for a web service or site. How difficult it will
be to do, and what you need to do to make your app publicly accessible, will
depend on the hosts TOS. It's definitely accomplishable with the vast
majority of hosts.

Personally, I prefer a host that gives me root on a box (or virtual
machine). I've had a great time with slicehost (http://slicehost.com).
However, going this route means that you'll have to learn quite a bit on the
sys-admin side. Slicehost has great articles written on various things, and
there's plenty of resources on the web (and in man pages) about what you
need to do to configure and secure a webserver, but it's still a lot of
learning. It is, however, stuff that you'll probably want to get familiar
with eventually anyhow, if you're writing web-facing python (or any other
language!).

There are a few hosts that specialize in, or explicitly offer python
hosting, http://wiki.python.org/moin/PythonHosting has an overview of them.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 7:44 AM, Mr. SpOOn <[EMAIL PROTECTED]> wrote:

> On Wed, Nov 19, 2008 at 1:35 PM, Jeremiah Dodds
> <[EMAIL PROTECTED]> wrote:
> >
> > Personally, I prefer a host that gives me root on a box (or virtual
> > machine). I've had a great time with slicehost (http://slicehost.com).
>
> Yes, I knew about slicehost, but it is expensive for what I need to
> do, that is just experimentin a bit.
>
> > There are a few hosts that specialize in, or explicitly offer python
> > hosting, http://wiki.python.org/moin/PythonHosting has an overview of
> them.
>
> Thanks for the link, seems useful.
>

If you need to do it on the extremely cheap, you can host on your own
machine on a port other than 80, make sure your router / firewall is
forwarding the port to your machine, and use dyndns (http://dyndns.com) to
give yourself a domain name. CherryPy (http://cherrypy.org) makes the python
side of hosting a simple service or app quite painless. I use this method to
host a little app for downloading Ubuntu packages and their dependencies as
a tarfile on my personal machine.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 8:35 AM, srinivasan srinivas <
[EMAIL PROTECTED]> wrote:

> Thanks,
> Srini
>
>
>  Add more friends to your messenger and enjoy! Go to
> http://messenger.yahoo.com/invite/
> --
> http://mail.python.org/mailman/listinfo/python-list
>

x = 2.99340584
y = abs(int(x) - x)
y
0.99340584

Is that what you wanted?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread Jeremiah Dodds
On Wed, Nov 19, 2008 at 8:58 PM, alex23 <[EMAIL PROTECTED]> wrote:

> On Nov 20, 10:14 am, Aaron Brady <[EMAIL PROTECTED]> wrote:
> > If you had a menu in a browser interface that had the items, say,
> > 'Stop' and 'Reload', what would you expect to happen if you clicked on
> > them?
>
> If you had a keyword called 'def', which defined functions, would you
> expect it to define said functions when it executed, or on each
> function call?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I think that most of the issue here stems from people not understanding the
"quirks" of "variable assignment" in python, not so much expecting the def
statement to get re-evaluated every time a function is called.

I'm willing to bet that people surprised by the behavior of def are also
surprised by:
a = [1,2,3]
b = a
b.append(4)
a
[1,2,3,4]

compared to:
a = 4
b = a
b = 5
a
4

This makes sense if you've read (and understood!) the docs, or if you're
familiar with other programming languages that have similar behavior, but a
lot of people learn python as a first language these days - and a lot of
those people learn it  largely by playing around, not by studying the
documentation. I can definitely see how the behavior could be confusing to a
newcomer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: String to sequence

2009-03-17 Thread Jeremiah Dodds
On Sat, Mar 14, 2009 at 9:09 AM, mattia  wrote:

> How can I convert the following string:
>
> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ'
>
> into this sequence:
>
> ['AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ']
>
> Thanks a lot,
> Mattia
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I don't know if I'm missing something or what in other peoples replies (they
seem unnecessarily complicated) or if what popped into my head would be a
bad idea, but I would do:

>>> s = "'AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
'EGC','SXF','BZR','BIQ','BLL','BHX','BLQ'"
>>> s.replace("'","").split(',')
['AAR',
 'ABZ',
 'AGA',
 'AHO',
 'ALC',
 'LEI',
 'AOC',
 'EGC',
 'SXF',
 'BZR',
 'BIQ',
 'BLL',
 'BHX',
 'BLQ']
--
http://mail.python.org/mailman/listinfo/python-list


Re: python book for a C programmer

2009-03-17 Thread Jeremiah Dodds
On Sat, Mar 14, 2009 at 5:10 AM, Saurabh  wrote:

> For introduction I am thinking about 'Learning Python' and for
> reference I am thinking about 'Python Bible'.
>
> I need your suggestions on this.
>
> Thanks in advance
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Here's another vote for "Python in a Nutshell" after the tutorial, it's an
excellent read, and perfect for someone who has a bit of experience with
other languages.
--
http://mail.python.org/mailman/listinfo/python-list


Re: REDIRECT

2009-03-18 Thread Jeremiah Dodds
On Wed, Mar 18, 2009 at 10:54 AM,  wrote:

> Hi !
>
> I'm new to Python. I'm having some difficulties to redirect the pages
> using python. Every time when I redirect, the URL changed accordingly.
>
> (Example : from   http://localhost:   to
> http://localhost/hello.py?name='J ')
>
> What's the Python way of implementing this ? Can anyone help me out on
> this ?
>
>
Depends on what framework you're using.

In CherryPy it would be:

raise cherrypy.HTTPRedirect("/hello?name='J'")

What are you using to build your webpage?
--
http://mail.python.org/mailman/listinfo/python-list


Re: REDIRECT

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 4:30 AM,  wrote:

> On Mar 18, 5:21 am, Tino Wildenhain  wrote:
> > gaeasian...@gmail.com wrote:
> >
>
> 3. GoogleAppEngine, Version 1.1.9
>   (webapp - framework)
>
> What actually I'm try to do is :
>
> I'm having a Login page which developed in HTML. When I click on the
> "Login" button I want the page to validate (at datastore of google
> app) using python and redirect to other HTML page. As what I
> understand, Python is the only language that supported by the
> GoogleApps.
>
>
http://code.google.com/appengine/docs/python/tools/webapp/redirects.html

Does that help?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 9:39 AM, Kottiyath  wrote:

> I understand that my question was foolish, even for a newbie.
> I will not ask any more such questions in the future.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I didn't think it was a foolish question, just one with a very subjective
(and perhaps unknowable) answer. I have a feeling that Daniel wasn't
intending to come off as snarky, but who knows.

What someone considers 'readable' or 'complex' is going to vary from
individual to individual. If you look at it (or if a peer on roughly the
same skill level as you looks at it) and has to squint really hard to figure
out what it's doing, it's probably not readable enough - which may or may
not be linked to the complexity of the code itself (Depending on how what
you mean by complexity - number of instructions? number of characters?
special charachters? number of tokens? levels of indirection? etc).
--
http://mail.python.org/mailman/listinfo/python-list


Re: read web page that requires javascript on client

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 1:25 AM, Carl  wrote:

> Probably the easiest thing is to actually use a browser. There are
> many examples of automating a browser via Python. So, you can
> programmatically launch the browser, point it to the JavaScript
> afflicted page, let the JS run and grab the page source. As an added
> bonus you can later interact with the page by programatically, filling
> form fields, selecting options from lists and clicking buttons.
>
> HTH, Carl
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I've been using the python port of mechanize (specifically
mechanize.browser) for web automation, it's rather nice.[1]

In the vast majority of cases, if I need something done with javascript,
it's just to generate a url or post data - in which case I can just read the
javascript, and figure out what it's doing - or use something like
livehttpheaders[2] to find out what I need to be sending.

This obviously doesn't cover every single case, but it works pretty fine
most of the time. I would love to see a complete javascript interpreter /
dom interface in python - but it's hard, hard stuff.

I'd love to even have the time to read the ECMAScript spec enough to have
enough working knowledge of javascript's internals to be able to contribute
to one of the current attempts at doing so.

1. http://wwwsearch.sourceforge.net/mechanize/
2. https://addons.mozilla.org/en-US/firefox/addon/3829
--
http://mail.python.org/mailman/listinfo/python-list


Re: python equivalent of java technologies

2009-03-19 Thread Jeremiah Dodds
On Tue, Mar 17, 2009 at 8:32 PM, Armin  wrote:

> You could tell her to try Jython.  In that, you can just use the Java
> implementations. :)  Plus, you have things in Jython that Java doesn't :D
>
> --
> Armin Moradi
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Exactly. Her challenges to find stuff have to do with the JVM, not Java the
language. Python runs on the JVM.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Use of HTMLparser to change language

2009-03-20 Thread Jeremiah Dodds
On Fri, Mar 20, 2009 at 9:59 AM, pranav  wrote:

> Greetings All,
>
> I have huge number of HTML files, all in english. I also have their
> counterpart files in Spanish. The non english files have their look
> and feel a little different than their english counterpart.
>
> My task is to make sure that the English HTML files contain the
> Spanish text, with retaining the English look and feel.
>
> The most obvious and stupid way is to open the English and Spanish
> files in some HTML Editor. Look for the english text, see its
> counterpart in spanish and then replace it. (I don't know spanish, but
> as i said the look and feel is only little different, so i can easily
> guess which text is what + google translate).
>
> I am sure there is a python way of solving this problem.
>
> Can anyone help me out with some solution.
>
> Thanks,
>
> Pranny
> --
> http://mail.python.org/mailman/listinfo/python-list
>


If you have things like unique div ids for where the text is (and the ids
are the same, or you can make them the same), you could use something like
BeautifulSoup to replace the english stuff programatically.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Introducing Python to others

2009-03-26 Thread Jeremiah Dodds
On Thu, Mar 26, 2009 at 9:35 AM, Paddy O'Loughlin <
patrick.olough...@gmail.com> wrote:

> Hi,
> As our resident python advocate, I've been asked by my team leader to
> give a bit of a presentation as an introduction to python to the rest
> of our department.
> It'll be less than an hour, with time for taking questions at the end.
>

> Any other suggestions for a possible "wow" reaction from an audience like
> that?
>
> Thanks,
> Paddy
>
> --
> "Ray, when someone asks you if you're a god, you say YES!"
> --
> http://mail.python.org/mailman/listinfo/python-list
>

The Genshi tut[1] uses CherryPy, and should be pretty "wowing" for primarily
php-devs, you could probably get some good ideas from there.

The biggest wow reactions I've gotten from php devs from showing them python
were when I showed them decorators (and explained how they work), and when I
showed them "raise cherrypy.HTTPRedirect('/somepath')".



[1] http://genshi.edgewall.org/wiki/GenshiTutorial
--
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging in Py

2009-03-26 Thread Jeremiah Dodds
On Wed, Mar 25, 2009 at 9:25 PM, *nixtechno  wrote:

> Big thanks tkc, and I was wondering what your thoughts are on logging
> module: http://docs.python.org/library/logging.html
>
> "Instead of using many print statements for debugging, use
> logger.debug: Unlike the print statements, which you will have to
> delete or comment out later, the logger.debug statements can remain
> intact in the source code and remain dormant until you need them
> again. At that time, the only change that needs to happen is to modify
> the severity level of the logger and/or handler to debug."
>
> Where it makes sense as they state using this rather than printing,
> due to the fact that you don't have to strip it all out when it's time
> to release your work... I seen some writing on pdb, but I guess it's
> time to study up on it. I appreciate the help.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I really like the logging module.  From the perspective of what you're
writing while you're working on part of an application, it tends to not be
that different that dropping print statements in, but there's a wealth of
flexibility and customizability available to you on the high level.

For instance, I use it at work for one of our applications, and it emails me
whenever certain types of events occur that I need to know about. It might
be overkill for small projects, but it's definately worth getting to know.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful soup : why does "string" not give me the string?

2009-04-01 Thread Jeremiah Dodds
On Wed, Apr 1, 2009 at 8:25 AM, Gabriel Rossetti <
gabriel.rosse...@arimaz.com> wrote:

> Hello everyone,
>
> I am using beautiful soup to parse some HTML and I came across something
> strange.
> Here is an illustration:
>
> >>> soup = BeautifulSoup(u'hello ça boume >>> soup
> hello ça boume
> >>> soup.find("div", "text")
> hello ça boume
> >>> soup.find("div", "text").string
> >>> soup.find("div", "text").next
> u'hello \xe7a boume'
>
> why does soup.find("div", "text").string not give me the string? Is it
> because there is a ?


IIRC, yes it is, and there's not much you can do about it other than  use
.next.string or .contents[0]  or stripping out brs. See
http://www.crummy.com/software/BeautifulSoup/documentation.html ,
particularly the "Removing Elements" and "string" sections.
--
http://mail.python.org/mailman/listinfo/python-list


Re: udp package header

2009-04-01 Thread Jeremiah Dodds
On Tue, Mar 31, 2009 at 6:19 PM, Artur M. Piwko
 wrote:

> In the darkest hour on Tue, 24 Mar 2009 00:50:10 + (UTC),
> R. David Murray  screamed:
> >> I got a problem. İ want to send udp package and get this package (server
> and
> >> clinet ). it's easy to python but i want to look the udp header how can
> i
> >> do ?
> >
> > The English word is 'packet'.
> >
> > If you are on Linux you can use raw sockets for this.
> >
>
> With a little drawback - raw sockets require root privilege.
>
>
Only some of them, or am I misinterpreting the term "raw socket"?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-01 Thread Jeremiah Dodds
On Wed, Apr 1, 2009 at 3:40 PM, 一首诗  wrote:


> What are the average size of source files in your project?   If it's
> far lower than 15,000,  don't feel it's a little unbalance?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

While I think 15,000 is, in the vast majority of cases, quite high, what
we're talking about here isn't about LOC, it's about whether or not things
are separated cleanly. I'm sure that sometimes that means a 15,000 line file
(although I can't think of a relevant example off the top of my head).

Whether or not the other files are a lot smaller doesn't matter. "Correctly"
organizing a project is more about separation of responsibility than
line-count.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Low level hard drive reading

2009-04-02 Thread Jeremiah Dodds
On Thu, Apr 2, 2009 at 12:36 PM, Gabriel  wrote:

> Hello,
> I have to write linux application that will analyze disk/partition (ext3
> filesystem) on really low level. It has to find/analyze files on the disk by
> reading disk blocks to analyze file's headers to find out file type and
>  then blocks related to file to  get file content. The second part have to
> be searching deleted files by this blocks reading (is this even possible?)
>
> Can i do this in python? For example can i open disk image file and read it
> block by block?
> Or is there even better solution? .) I tried search web but I wasn't
> successful..
>
> I will appreciate any help. Thank you in advice..
>
> Gabriel
> --
> http://mail.python.org/mailman/listinfo/python-list


I may be wrong, but I'd assume that you could just read by block size,
opening the file that represents the disk in /dev (/dev/sda or similar). I
don't see why you would want to do that to find out file type/headers
though. You should be able to see the contents of "deleted" files that
haven't been (entirely) overwritten on disk - I believe that when you delete
a file, you really just delete the inode, or reference that tells the
filesystem that there's a file there.

Someone else who's keener on the details of these things will probably come
with better information.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-02 Thread Jeremiah Dodds
The one thing that makes me want to use git more than any other dvcs is that
you don't have to create a new directory for branches. This may be possible
in other dvcs's , but git is the only one I've seen advertise the
capability.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-03 Thread Jeremiah Dodds
On Thu, Apr 2, 2009 at 9:02 PM, andrew cooke  wrote:

> Echo wrote:
> > 2009/4/2 Jeremiah Dodds 
> >
> >> The one thing that makes me want to use git more than any other dvcs is
> >> that you don't have to create a new directory for branches. This may be
> >> possible in other dvcs's , but git is the only one I've seen advertise
> >> the
> >> capability.
> [...]
> > That is the main reason why I switched to git at my work.
> > As for the git rebase, I don't ever plan on using that 'feature'. Even
> > though I would rather have had GvR pick git, I think he did a good job
> > deciding.
>
> please can you explain this?  i can think of a couple of things you could
> mean, but neither of them seem to make much sense to me.
>
>
> one is that hg only allows you one branch per repository.  i checked the
> docs and that's not true - see 2/3 way down
>
> http://hgbook.red-bean.com/read/managing-releases-and-branchy-development.html
> - which describes how you can branch in the repository and then swap your
> working copy between them.
>

It looks like basically the same thing is accomplishable in hg, but is a bit
discouraged (I am not experienced with hg, and haven't read the docs
thoroughly, so I could be off base here). In most (d)vcs's , there is
normally a one-to-one relationship between project branches and directories
on your filesystem. In git, there is normally a many-to-on relationship
between project branches and directories on your filesystem - branching is
cheap and easy, and you can branch for every little fix or feature you want
to do, keeping one directory with multiple logical development paths with
basically no pain.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python2.4 and HTTPS

2009-04-06 Thread Jeremiah Dodds
On Sun, Apr 5, 2009 at 8:17 AM, Good Z  wrote:

> Dear all,
> I am using Python 2.4.3 for my project. We need to use HTTPS with
> python2.4.3 unfortunately it seems httplib is not working fine for me. Below
> is small code that works well with Python2.6.1 but not with Python2.4.3.
> Unfortunately its not possible for me to move away from Python 2.4.3. Would
> request if anyone has any idea how to make this programs work in
> Python2.4.3.
>
> import httplib
> conn1 = httplib.HTTPSConnection(WEBSITE_ADDRESS)
> conn1.putrequest('GET', RELATIVE_ADDR)
> conn1.putheader('Connection', 'close')
> conn1.endheaders()
>
> r1 = conn1.getresponse()
>
> data1 = r1.read()
> print data1
> conn1.close()
>
> One executing the above program, it crash while reading the response and
> gives following error:
> Traceback (most recent call last):
>   File "", line 1, in 
> r1 = conn1.getresponse()
>   File "C:\Python25\lib\httplib.py", line 928, in getresponse
> response.begin()
>   File "C:\Python25\lib\httplib.py", line 385, in begin
> version, status, reason = self._read_status()
>   File "C:\Python25\lib\httplib.py", line 349, in _read_status
> raise BadStatusLine(line)
> BadStatusLine
>
> Any help would be appreciated.
>
> Best Regards,
> Mike.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

You may be running into http://bugs.python.org/issue5007  - if you could
post the url of the site you're trying to open, I can test to see if it
works in 2.5/2.6 (It won't if you're running into that bug).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Retrieving a specific object from a list?

2009-04-09 Thread Jeremiah Dodds
On Thu, Apr 9, 2009 at 12:16 PM, andrew cooke  wrote:

> but when you need to access instances by more than one value (.bar and
> .baz) then typically that's a hard problem, and there's a trade-off
> somewhere.  you might find writing a special container that contains two
> dicts is useful.  if so, you might want to use weak references - see
> weakref module).
>
> all the above are relatively direct solutions.  in my experience this kind
> of issue often comes from not thinking at a high enough level about the
> algorithm - even though my third suggestion (deque) sounds rather obscure
> you may find that once you look at you algorithm more carefully it can be
> rewritten in that way.  i think i've seen this in my own code as i improve
> at integrating what might be more "functional" idioms into python in a
> "natural" (pythonic) way.
>
> andrew
>
>
Thanks, I have used a dict for doing what I was talking about in cases where
I only ever want to be able to access by one property of the objects, but as
you know, that doesn't work too well when I want to access by more than one
property.

It looks like I need to write a special class that acts as an iterable, and
as a map on values of (more-or-less) arbitrary properties of the objects
contained in it. I could probably also use with stepping back and looking at
my problem from a higher level to make sure I'm not barking up an entirely
wrong tree.

I'll take a look at weakref and dequeue, and see if they help.
--
http://mail.python.org/mailman/listinfo/python-list


Retrieving a specific object from a list?

2009-04-09 Thread Jeremiah Dodds
I've been looking over some of my code, and I've found something I do that
has a bit of a smell to it. I've searched the group and docs, and haven't
found much of anything that solves this particular problem, although I may
just not be searching correctly.

Anyhow, I find that often I'll have a list of objects of some sort that I
want to operate on. Most of the time, I'll want to operate on the entire
list, but sometimes I'll want to operate on just one element, or retrieve
just one element, and I end up with code something like the following:

items = [Foo(), Foo(), ... Foo()]

a_item = [x for x in items if x.bar == some_value][0]
another_item = [x for x in items if x.baz == some_other_value][0]

This doesn't seem correct at all, looping over the entire list to create a
list of one element and then pulling that item out. Any advice?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Something weird about re.finditer()

2009-04-15 Thread Jeremiah Dodds
On Wed, Apr 15, 2009 at 9:46 AM, Gilles Ganault  wrote:

> Hello
>
>I stumbled upon something funny while downloading web pages and
> trying to extract one or more blocks from a page: Even though Python
> seems to return at least one block, it doesn't actually enter the for
> loop:
>
> ==
> re_block = re.compile('before (.+?) after',re.I|re.S|re.M)
>
> #Here, get web page and put it into "response"
>
> blocks = None
> blocks = re_block.finditer(response)
> if blocks == None:
>print "No block found"
> else:
>print "Before blocks"
>for block in blocks:
>#Never displayed!
>print "In blocks"
> ==
>
> Since "blocks" is no longer set to None after calling finditer()...
> but doesn't contain a single block... what does it contain then?
>
> Thank you for any tip.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


It contains an iterator. It's just an iterator with nothing in it:

In [232]: import re

In [233]: re_block = re.compile('before (.+?) after',re.I|re.S|re.M)

In [234]: blocks = None

In [235]: blocks = re_block.finditer('Hi There Im not going to match
anything')

In [236]: blocks
Out[236]: 

In [237]: blocks == None
Out[237]: False

In [238]: for block in blocks:
   .: print block
   .:

In [239]: type(blocks)
Out[239]: 

In [241]: blocks.next()
---
StopIteration Traceback (most recent call last)

/home/jeremiah/ in ()

StopIteration:


Maybe you should just use a different method, like findall, where you can
check the length of it. Or, if you don't need to do anything special when
there aren't any blocks, you could continue like this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: get text from rogramms runn by subprocess.Popen immediatetly

2009-04-16 Thread Jeremiah Dodds
On Thu, Apr 16, 2009 at 12:12 PM, Rüdiger Ranft <_r...@web.de> wrote:

> Hi all,
>
> I need to call some programms and catch their stdout and stderr streams.
> While the Popen class from subprocess handles the call, I get the
> results of the programm not until the programm finishes. Since the
> output of the programm is used to generate a progress indicator, I need
> a way to acces the values written to stdout/stderr as fast as possible.
>
> Beneath is a test which shows what I did
>
> TIA
> Rudi
>
> 8<---8<---8<-- iodummy.cpp -8<---8<---
> #include 
> #include 
>
> int main()
> {
>for( int i = 0; i < 10; i++ )
>{
>std::cerr << i << std::endl;
>sleep(2);
>}
> }
>
> from subprocess import Popen, PIPE
> from time import sleep
>
> p = Popen('./iodummy',stdin=PIPE, stdout=PIPE, stderr=PIPE)
> sleep(3)
> # now I expect '0\n1\n' in stderr, but read() blocks until
> # the end of iodummy.
> print p.stderr.read()
> p.wait()
>
> --
> GPG encrypted mails preferred.
> GPG verschlüsselte Mails bevorzugt.
> ---> http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 <
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

Depending on what exactly you're doing (like if you need to send info back
to the program you're spawning), the socket module might be of use. I use it
to communicate between Perl and Python for some stuff I have to do at work,
and it works out rather well.

Specifically, I've found sockets and JSON to work really nicely for
inter-language program communication.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Language detection with python

2009-04-17 Thread Jeremiah Dodds
On Fri, Apr 17, 2009 at 3:19 PM, S.Selvam  wrote:

> Hi all,
>
> I am trying for language detection in python.I just need to check whether
> the input text is english or not.
>
> 1)I tried nltk's stopwords and compared with input text,but only with
> little success.
>
> 2)Used oice.langdet for language detection,which uses bi-gram approach.It
> is also inefficient.
>
> I need a best way to detect english text .
>
> I welcome your suggestions ...
> --
> Yours,
> S.Selvam
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

I don't know anything about language detection, but my first attempt would
be something like:

Grab the first N words (space-separated) from whatever file you're trying to
check
Find out what percentage of them, if any, are in some dictionary file, say
/usr/share/dict/american-english on Ubuntu linux.

If there's a high percentage of words found, it's more than likely english.

Or, perhaps checking for some commonly used words in english that only
appear in english. I'm not aware of any examples off the top of my head, as
I only know one language, but I'm sure there are some common english words
that are mostly unique to the language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: when can i expect libraries and third party tools to be updated for python 3 ?

2009-04-20 Thread Jeremiah Dodds
On Mon, Apr 20, 2009 at 3:40 PM, Stefan Behnel  wrote:

> alessiogiovanni.baroni wrote:
> > On 20 Apr, 15:47, Deep_Feelings wrote:
> > > every one is telling "dont go with python 3 , 3rd party tools and
> > > libraries have no compitability with python 3"
> > >
> > > so from previous experience : when can i expect libraries and third
> > > party tools to be updated for python 3 ? (especially libraries )
> >
> > When the authors of a every library wants update to 3 :-D.
>
>
> ... or give a hand to the projects you need, if you don't want to sit and
> wait.
>
> Stefan
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I think this is the key, really. I see a lot of people asking about when
libraries will get ported to python 3, and it seems to me like a lot of
people could just do a little reading on the tools provided for migrating,
pull the dev version of the library, and take a crack at it.

I'm sure the various library authors would be appreciative.

Of course, it's probably hard for a lot of people to find time to do so
(this does not exclude the library authors), and a good amount of the people
asking probably aren't quite to the point that they could just dive in to an
unfamiliar codebase.

I would say that porting libraries to 3 would probably be a decent way of
improving ones python chops though.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python standard library and PEP8

2009-04-20 Thread Jeremiah Dodds
On Mon, Apr 20, 2009 at 2:18 PM, Scott David Daniels
wrote:

> Steven D'Aprano wrote:
>
>> ... There's an accepted definition for "objected oriented programming
>> language": a language which provides "objects", which are constructs
>> encapsulating both data and routines to operate on that data in a single
>> item.
>>
> Says you. Roger King wrote a book entitled "My Cat is Object-Oriented."
> His basic premise is that, while everyone understands what you mean
> when you say something is object-oriented, everyone's understanding is
> different.
>
> --Scott David Daniels
> scott.dani...@acm.org
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Also see  http://c2.com/cgi/wiki?NobodyAgreesOnWhatOoIs
--
http://mail.python.org/mailman/listinfo/python-list


Re: Essential tools for Python development

2009-04-22 Thread Jeremiah Dodds
On Wed, Apr 22, 2009 at 3:50 AM, Esmail  wrote:

> Great list Ben, I use emacs and will check out the tools
> you listed.
>
> What techniques/tools do you recommend for debugging?
>
> Esmail
> --
> http://mail.python.org/mailman/listinfo/python-list
>

pdb is good if you need to do step-through debugging.

What I normally do in emacs is the following (while working on python
script, and with the python-mode that comes with emacs22):

C-x 3  #splits the screen into two vertical columns
C-c C-c   #fires up python and sends the current buffer to it
C-x o  #switches to the other column
C-x b Py #switches to the python interactive buffer

This is, I do believe, equivalent to running a script with python -i
script.py . Drops you into an interactive session where you can interact
with what you just wrote. Another very handy tool is etags, see the help in
emacs (You can get to it through C-h i m emacs)
--
http://mail.python.org/mailman/listinfo/python-list


Re: need help with a multiloop error

2009-04-22 Thread Jeremiah Dodds
On Wed, Apr 22, 2009 at 3:07 PM, Brian  wrote:

> I'm trying to run a python program with a multiloop and I am getting
> this error message.  I was wondering if anyone could tell from this
> message what I'm doing wrong or where I've made a mistake.  Let me
> know if you need some of the code for this to make more sense.  Thanks
> a lot.
>
>
> How much labor time does each individual have?8
> 1331
> Traceback (most recent call last):
>
>  File "C:\Python25\commodity\commoditytrading4.2.py  commoditytrading4.2.py> ", line 233, in 
>
>options = mp.options(all,names)
>  File "C:\Python25\commodity\multipleloop.py", line 265, in options
>for name, value in zip(names, experiment)]))
>  File "C:\Python25\commodity\misc.py", line 244, in str2obj
>b = str2bool(s)
>  File "C:\Python25\commodity\misc.py", line 155, in str2bool
>(s, type(s))
> TypeError: 0.0  cannot be converted to bool
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I think we'd have to see your str2* functions. I'm a bit confused as to why
they exist anyhow, as the normal "if foo" tends to work in most situations.

What are you trying to do? Why do you need str2obj, and str2bool? I'm
betting that there's a much better way to solve what you're trying to, but
we're going to need some more info (and code) to help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Configuring pylint for local conventions (was: pyflakes, pylint, pychecker - and other tools)

2009-04-23 Thread Jeremiah Dodds
On Thu, Apr 23, 2009 at 2:58 PM, Ben Finney

> wrote:

> a...@pythoncraft.com (Aahz) writes:
>
> > Second, you can configure pylint to respect your personal style
>
> How? I haven't seen any decent documentation on doing so.
>
> --
>  \  “When we call others dogmatic, what we really object to is |
>  `\   their holding dogmas that are different from our own.” —Charles |
> _o__)   Issawi |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list


I'm fairly certain that ~/.pylint.rc is just the command line options
available to pylint made into a conf file.

See  http://flexget.com/browser/trunk/pylint.rc?rev=475 for an example.

So, for a section from pylint --help like so:

 Miscellaneous:
--notes=
List of note tags to take in consideration,
separated
by a comma. [current: FIXME,XXX,TODO]

You would make a configuration item like so:

[MISCELLANEOUS]
notes=FIXME,TODO

This is a fairly common thing for command-line app configurations.
--
http://mail.python.org/mailman/listinfo/python-list


Re: value error

2009-04-23 Thread Jeremiah Dodds
On Thu, Apr 23, 2009 at 3:59 PM, Francesco Pietra wrote:

> hi:
> with script
>
> data = open('134-176_rectified_edited.pdb', 'r')
> outp = open('134-176_renumbered.pdb', 'w')
>
> for L in data:
>   if L[3] == 'M':
> L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:]
>   outp.write(L)
>
>
> i wanted to modify lines of the type:
> ATOM  1 HH31 ACE 1   1.573   1.961   0.769  1.00  0.00
>   H
>
> to add 133 to column 25, getting 134 there, and so on for next lines 2
> -> 135, 3 -> 136, etc.
>
>
> i must have heavily messed things because the file was not even read:
>
> $ python renumber.py 134-176_rectified.pdb
> Traceback (most recent call last):
>  File "renumber.py", line 6, in 
>L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:]
> ValueError: invalid literal for int() with base 10: ''
>
>
>
> thanks for having an expert look
>
> chiendarret
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I wrote this function the other day for something similar I needed to do,
you may find it useful:

def chunk_line(line, steps):
"""Return a list of chunks from a string, with sizes as specified by the
list steps.

>>> line = '1121231234'
>>> steps = [1,2,3,4]
>>> chunk_line(line, steps)
['1', '12', '123', '1234']
"""
result = []
for step in steps:
result.append(line[:step])
line = line[step:]
return result
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you think of ShowMeDo

2009-04-29 Thread Jeremiah Dodds
On Wed, Apr 29, 2009 at 6:48 AM, Banibrata Dutta
wrote:

> Personally, I faced some despair with a large number of the free
> ShowMeDo tutorials, example the one on WxPython, where for the first 4
> free tutorials, the tutor hardly progresses to any bit of programming,
> and what is demonstrated was too basic, too slow - to hold my
> attention.
>

I must agree here. I'll add that the vast majority of video tutorials or
lectures that I've seen are way too slow to hold my interest, with the
exception of google tech talks, and stuff like OCW from MIT. (These are at
http://research.google.com/video.html and
http://ocw.mit.edu/OcwWeb/web/home/home/index.htm respectively).

However, I do really like the idea of showmedo, especially for people who
like learning through not-so-dense video on the introductory level. I
haven't been incredibly impressed with the quality of the free stuff there
either, but I also haven't looked at any of the paid stuff. I don't think
that it's safe to assume that it's of a substantially higher quality.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web Based Front End?

2009-05-08 Thread Jeremiah Dodds
On Fri, May 8, 2009 at 2:52 AM,  wrote:

> So, my question is what is the best method to be able to have a user
> enter specific data on a web page, have that data be passed to the
> Python script and then have the output returned to the web page?
> Essentially, I want to use a web based front end to accomplish the
> same thing that the IDLE GUI does, (asks me a few questions, I answer
> them, it builds a configuration file and prints it to the screen).
>
>
There isn't a best way, really.

I'm partial to CherryPy. A minimal example would look like so:

---
import cherrypy

class Root(object):
page = "%s"
@cherrypy.expose
def enter_data(self, data):
return self.page % ("You entered: " + data,)

@cherrypy.expose
def index(self):
form = """

  Enter some stuff here
  

"""
return self.page % form

if __name__ == '__main__':
cherrypy.quickstart(Root())

---

Note, I wouldn't actually recommend using string building like that for
returning pages unless your app is seriously trivial. I use Genshi for
templating, the tutorial that they have is very nice (and uses cherrypy).

There's a plethora of different ways to build web apps in python. In all
reality, you should probably try out a few and see what suits your tastes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Your Favorite Python Book

2009-05-12 Thread Jeremiah Dodds
On Mon, May 11, 2009 at 9:44 PM, Sam Tregar  wrote:

> Greetings.  I'm working on learning Python and I'm looking for good books
> to read.  I'm almost done with Dive into Python and I liked it a lot. I
> found Programming Python a little dry the last time I looked at it, but I'm
> more motivated now so I might return to it.  What's your favorite?  Why?
>
> -sam
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
I've gotten great use out of Programming Python (mainly because it has a lot
of larger full-fledged examples), Python in a Nutshell, and recently Expert
Python Programming. My copy of Python in a Nutshell is particularly
dog-eared now - it is a bit outdated (I've got notes all over the book of
things that have changed...) but it's still a great resource.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fill Javascript form

2009-05-12 Thread Jeremiah Dodds
On Tue, May 12, 2009 at 9:15 AM, Matteo  wrote:

> On 11 Mag, 23:06, Shawn Milochik  wrote:
> > How is the form "written in JavaScript"? Is it dynamically generated?
> >
> > In any case, can you just send a POST request if you know the values
> required?
>
> The problem is indeed that the form is dynamically generated.
> That's the .js file:
>
> if (navigator.appVersion.indexOf("MSIE")!=-1)
> document.write("

Re: Generic web parser

2009-05-18 Thread Jeremiah Dodds
On Sat, May 16, 2009 at 2:18 PM, S.Selvam  wrote:

> Hi all,
>
> I have to design web parser which will visit the given list of websites and
> need to fetch a particular set of details.
> It has to be so generic that even if we add new websites, it must fetch
> those details if available anywhere.
> So it must be something like a framework.
>
> Though i have done some parsers ,but they will parse for a given
> format(For. eg It will get the data from  tag).But here each website
> may have different format and the information may available within any tags.
>
> I know its a tough task for me,but i feel with python it should be
> possible.
> My request is, if such thing is already available please let me know ,also
> your suggestions are welcome.
>
> Note: I planned to use BeautifulSoup for parsing.
>
> --
> Yours,
> S.Selvam
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
I'd recommend mechanize in combination with BeautifulSoup - it greatly
simplifies most web-scraping tasks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strip char from list of strings

2009-05-19 Thread Jeremiah Dodds
On Mon, May 18, 2009 at 8:30 PM, Laurent Luce wrote:

>
> I have the following list:
>
> [ 'test\n', test2\n', 'test3\n' ]
>
> I want to remove the '\n' from each string in place, what is the most
> efficient way to do that ?
>
> Regards,
>
> Laurent
> --
> http://mail.python.org/mailman/listinfo/python-list
>


>>> s = [ 'test\n', test2\n', 'test3\n' ]
>>> [i.strip() for i in s]

['test', 'test2', 'test3']

>>> map(str.strip, s)

['test', 'test2', 'test3']


I'm not sure which one of these is more efficient, but it probably doesn't
really matter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Jeremiah Dodds
On Mon, May 25, 2009 at 6:35 PM, LittleGrasshopper
wrote:

> With so many choices, I was wondering what editor is the one you
> prefer when coding Python, and why. I normally use vi, and just got
> into Python, so I am looking for suitable syntax files for it, and
> extra utilities. I dabbled with emacs at some point, but couldn't get
> through the key bindings for commands. I've never tried emacs with vi
> keybindings (I forgot the name of it) but I've been tempted.
>
> So what do you guys use, and why? Hopefully we can keep this civil.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I, like some others on this list, use emacs.

I've heard that vi (well, vim) makes a pretty nice python editor though. If
you're comfortable with it, keep using it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-27 Thread Jeremiah Dodds
On Wed, May 27, 2009 at 6:29 AM, Teguh Iskanto  wrote:

>
>
> BTW: "screen" does split screen too :)
>
> HTH
>
>
Unfortunately, screen only does horizontal splitting. (I heard that vertical
splitting is supposed to be in the next version of it, and is in the dev
trunk, but I don't know).

That said, screen is possibly the second most useful tool in my toolbox,
right behind emacs. If you need to interact with different machines, it's a
lifesaver. Actually, even if you don't, but you find yourself with a bunch
of terminals open (whether you're in X or not), it's still incredibly
useful.

I know this is supposed to be a discussion about text editors, but I think
that screen does deserve a mention as being very complementary to a good
text editor if you're a programmer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: popen question

2009-05-28 Thread Jeremiah Dodds
On Thu, May 28, 2009 at 9:11 AM, Sean DiZazzo wrote:

> On May 27, 6:10 pm, thebiggestbangthe...@gmail.com wrote:
> > hello everyone :-),
> >  I am a newbie to python. I am trying to run a
> > bash script from within a python program. I would greatly appreciate
> > any pointers/comments about how to get around the problem I am facing.
> >
> > I want to run  bash script: code.sh from within a python program.
> > code.sh needs to be run like so from the command line
> > [code]
> > $ sudo code.sh arg1 arg2
> > [/code]
> >
> > I read up on some documentation but am not very clear about how to use
> > popen. I want to relegate the shell to a background process, but it
> > needs to accept the sudo passwd too!
> >
> > I have tried
> > [code]
> > p = subprocess.Popen(['/bin/bash', 'sudo '+mypath+'code.sh '+arg1+'
> > '+arg2],
> > stdout=subprocess.PIPE,
> > stderr=subprocess.STDOUT)
> > [/code]
> > I tried some code from stackoverflow.com/questions/694000/why-doesnt-
> > subprocess-popen-always-return
> >
> > nothing really happens when this executes, the PIPE option pshes it to
> > the background and I can't push in the sudo passwd. Can someone please
> > give me an idea of how to go about this.
> >
> > To recap, I want to run a shell script, which needs to be started with
> > sudo, and then push it into the background.
> >
> > Thanks,
> > -A
>
> Your best bet is to make sudo not ask for a password.  :)  If you
> don't have the rights, then you can use pexpect to do what you want to
> do.  http://pexpect.sourceforge.net/pexpect.html
>

Whoah there. Pexpect, yes. Making sudo not ask for a password? Only if you
tell sudo to only not ask for a password for _this_ file. Telling sudo to
not require a password at all is asking for trouble.

Also, modifying sudo to allow this script to run without a password would
require that to be done on every machine that the OP wants to run on.

OP: use pexpect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: automated web with python?

2009-06-01 Thread Jeremiah Dodds
On Mon, Jun 1, 2009 at 8:26 AM, P. Kaminski  wrote:

> Ech... The problem is that mechanize doesn't support JavaScript, and
> these web forms are full of various JS functions... Maybe someone
> knows a way out of this? Doesn't have to be Python...
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Selenium _might_ be able to help you out.

Otherwise, a method you can use (tedious at first, but can speed things up
significantly) would be to either use firefox and grab the headers you're
sending during a session (the site may use javascript really heavily, but in
the end all that matters is that you're sending the same POST/GET requests),
and then use mechanize, or read the javascript, and then use mechanize.

At my job, I've had to automate a few really javascript-heavy web
applications. Firefox+FireBug+HTTPFox with python and mechanize can be a
lifesaver here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to develop a python application?

2009-06-05 Thread Jeremiah Dodds
On Fri, Jun 5, 2009 at 4:12 AM, Vincent Davis wrote:

> This might be a off topic but this also seemed like a good place to ask.
>
> I have an application (several) I would like to develop. Parts of it I
> can do but parts I would like to outsource. I am thinking mostly of
> outsourcing most of my django (or similar) work and otherwise have
> some custom classes written.
> I would like to do this small bits (that is the out sourcing) at a
> time for many reasons but I realize there are down sides to doing this
> (I probably don't know all them)
>
> I have a this specific project in mind but don't mind this topic being
> rather broad. I would like to read and learn more about developing
> software (commercial or open source)
>
> My questions
> How do I find programs interested in small projects.
> How do they expect to be paid or how should I pay.
> Are sites like elance.com good?
> What do I not know to ask? That is what should I be considering?
>
> Any suggestions would be appreciated.
>
>
>
> Very brief description of the project.
> The app would take GPS, Heartrate, Power(bicycle) data from a Garmin
> GPS and other devises and upload it to a database. After that I have
> several calculations and analysis of the data. Then display graphs and
> other statistics. This is a very brief explanation.
>
> There are several examples of similar python projects, but not web based.
> Granola
> pygarmin
> garmin-sync
> The closest web based example would be Training Peaks
>
> http://home.trainingpeaks.com/personal-edition/training-log-and-food-diary.aspx
>
> Thanks
> Vincent Davis
> 720-301-3003
> --
> http://mail.python.org/mailman/listinfo/python-list
>


With regards to sites like elance, I can only offer advice here from a
coder's perspective, so I may be missing some things, but here goes:

You can probably find people on elance or rentacoder, or similar sites to
work on your app. You will need to be very careful about who you hire though
- the sites are filled with incompetent coders, and bots that represent
_teams_ of incompetent programmers.

I used to do a good bit of work on sites like that, and a lot of my work was
fixing apps that got written by other people on those sites that had no idea
what they were doing. We're talking about 10,000 lines of PHP that got
changed into ~2500 with simple, mostly automated refactoring because the
people who wrote it had apparently never heard of a for loop.

Payment is normally done through an escrow service. The price you're willing
to pay generally gets decided on before work begins, and the people who want
to work on it can make bids saying how much they want for the work, and you
can talk to them - make sure they know what they're talking about, haggle
price, etc. There tends to be protection for both the person paying and the
person working to avoid you not paying them if they did what they were
supposed to, and to avoid you having to pay them if they didn't.

All in all, using sites like elance can get your work done, and it can get
it done well and on the cheap - but you'll have to spend a significant
amount of time weeding through automated responses and making sure you're
getting the right person to work on your stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python3.1

2009-06-11 Thread Jeremiah Dodds
On Wed, Jun 10, 2009 at 10:33 PM, Johannes Bauer wrote:

> Martin v. Löwis schrieb:
> >> What can I do about that?
> >
> > Remove the non-ASCII characters from db.h.
>
> Ehh...
>
> $ find -type f | grep -i db.h
>

OT:

find -type f -iname "db.h"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009

2009-06-19 Thread Jeremiah Jester
Chris,
Do you have any online tutorial for this topic? 
Thanks,
JJ

On Thu, 2009-06-18 at 08:38 -0700, Chris Withers wrote:
> Hi All,
> 
> Too many people in the Python community *still* think the only way to
> work with Excel files in Python is using COM on Windows.
> 
> To try and correct this, I'm giving a tutorial at this year's
> EuroPython
> conference in Birmingham, UK on Monday, 29th June that will cover
> working with Excel files in Python using the pure-python libraries
> xlrd,
> xlwt and xlutils.
> 
> I'll be looking to cover:
> 
> - Reading Excel Files
> 
>Including extracting all the data types, formatting and working
> with
>large files.
> 
> - Writing Excel Files
> 
>Including formatting, many of the useful frilly extras and writing
>large excel files.
> 
> - Modifying and Filtering Excel Files
> 
>A run through of taking existing Excel files and modifying them in
>various ways.
> 
> - Workshop for your problems
> 
>I'm hoping anyone who attends will get a lot out of this! If you're
>planning on attending and have a particular problem you'd like to
> work
>on in this part of the tutorial, please drop me an email and I'll
> try
>and make sure I come prepared!
> 
> All you need for the tutorial is a working knowledge of Excel and
> Python, with a laptop as an added benefit, and to be at EuroPython
> this
> year:
> 
> http://www.europython.eu/
> 
> I look forward to seeing you all there!
> 
> Chris
> 
> --
> Simplistix - Content Management, Zope & Python Consulting
> - http://www.simplistix.co.uk
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-announce-list
> 
> Support the Python Software Foundation:
> http://www.python.org/psf/donations.html
> 
> 
> 


Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining if a function is a method of a class within a decorator

2009-07-02 Thread Jeremiah Dodds
On Wed, Jul 1, 2009 at 2:14 AM, David Hirschfield  wrote:

>  Unfortunately that still requires two separate decorators, when I was
> hoping there was a way to determine if I was handed a function or method
> from within the same decorator.
>
> Seems like there really isn't, so two decorators is the way to go.
> Thanks,
> -David
>
>
This is a really horrible idea, but it may work:

If you can rely on your code using the word "self", you could use the
inspect module to look at the arguments of the function being decorated, and
dispatch based on that. The idea itself feels extremely dirty though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling functions: Why this complicated ?

2009-07-15 Thread Jeremiah Dodds
On Wed, Jul 15, 2009 at 1:42 AM, Mohan Parthasarathy wrote:

> So, all four of them above has its use cases in practice i guess.
>
> thanks
> mohan
>

As a hopefully semi-informative aside, I've been writing python code for a
few years now, and I regularly use all four forms of argument passing listed
above.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling functions: Why this complicated ?

2009-07-15 Thread Jeremiah Dodds
On Wed, Jul 15, 2009 at 11:54 AM, Tim Rowe  wrote:

>
> Curiously, I never use the all-named style in Python, whereas it's my
> normal style in Ada. I shall now enter a period of self-refelection to
> try to work out why I am so inconsistent :-)
>
>
>
I use it for functions that only (or mostly) have behaviour-modifying flags
and for functions that take more than 3 or so parameters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Jeremiah Dodds
"Ben S. via Python-list"  writes:

> Can I somehow check from inside a Python script if the executing Python 
> engine is major version v2 or v3?

import sys
sys.version_info[0]

(If you just need to print() consistently, you should follow Terry's advice)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic python understanding

2017-07-26 Thread Jeremiah Dodds
monica.sn...@gmail.com writes:

> What would be some questions and answers so I gain a strong
> understanding of my candidate that has Python experience?

In addition to the resources others have pointed you at, it's worth
mentioning that it can be very hard to gauge experience past the basics
if you don't have it yourself.

If you currently have python developers at your company, it's worth
considering having one of them sit in on the interview or review the
candidate with you -- you'll be able to get a more accurate read on the
experience level of the candidate, and I'd imagine it'd be a help at
getting familiar with the types of things that you can be looking for
that indicate a good hire.



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python parser overridden by pymol

2009-11-12 Thread Jeremiah H. Savage
On Wed, Nov 11, 2009 at 7:48 PM, Dave Angel  wrote:
>
>
> Jeremiah wrote:
>>
>> Hello,
>>
>> I'm fairly new to python (version 2.5.4), and am writing a program
>> which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from
>> debian.
>>
>> It appears that when I add pymol to $PYTHONPATH, that parser.expr() is
>> no longer available, and so I am unable to use numpy.load(). I have
>> looked for where parser.expr() is defined in the python system so I
>> could place that directory first in $PYTHONPATH, but I have not been
>> able to find the file that defines expr().
>>
>> My reason for using numpy.load() is that I have a numpy array which
>> takes an hour to generate. Therefore, I'd like to use numpy.save() so
>> I could generate the array one time, and then load it later as needed
>> with numpy.load().
>>
>> I've successfully tested the use of numpy.save() and numpy.load() with
>> a small example when the pymol path is not defined in $PYTHONPATH  :
>>
>>   >>> import numpy
>>   >>> numpy.save('123',numpy.array([1,2,3]))
>>   >>> numpy.load('123.npy')
>>   array([1, 2, 3])
>>
>>
>> However, a problem arises once $PYTHONPATH includes the pymol
>> directory. To use the pymol api, I add the following to ~/.bashrc:
>>
>>   PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
>>   export PYMOL_PATH
>>   PYTHONPATH=$PYMOL_PATH
>>   export PYTHONPATH
>>
>> Once this is done, numpy.load() no longer works correctly, as pymol
>> contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/
>> parser.py ), which apparently prevents python from using its native
>> parser.
>>
>>   >>> numpy.load('123.npy')
>>   Traceback (most recent call last):
>>     File "", line 1, in 
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line
>> 195, in load
>>       return format.read_array(fid)
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
>> line 353, in read_array
>>       shape, fortran_order, dtype = read_array_header_1_0(fp)
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
>> line 250, in read_array_header_1_0
>>       d = safe_eval(header)Thank you. That really helped.

To use pymol and numpy to
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line
>> 840, in safe_eval
>>       ast = compiler.parse(source, "eval")
>>     File "/usr/lib/python2.5/compiler/transformer.py", line 54, in
>> parse
>>       return Transformer().parseexpr(buf)
>>     File "/usr/lib/python2.5/compiler/transformer.py", line 133, in
>> parseexpr
>>       return self.transform(parser.expr(text))
>>   AttributeError: 'module' object has no attribute 'expr'
>>
>> If I understand the problem correctly, can anyone tell me where
>> python.expr() is defined, or suggest a better method to fix this
>> problem?
>>
>> Thanks,
>> Jeremiah
>>
>>
>
> Generic answers, I have no experience with pymol
>
> If pymol really needs that parser.py, you have a problem, as there can only
> be one module by that name in the application.  But assuming it's needed for
> some obscure feature that you don't need, you could try the following
> sequence.
>
> 1) temporarily rename the pymol's  parser.py  file to something else, like
> pymolparser.py, and see what runs.
> 2) rather than changing the PYTHONPATH, fix  up  sys.path during your script
> initialization.
>   In particular, do an    import parser    near the beginning of the script.
>  This gets it loaded, even though you might not need to use it from this
> module.
>   After that import, then add the following line (which could be generalized
> later)
>   sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
>
>
> If this works, then you can experiment a bit more, perhaps you don't need
> the extra import parser, just putting the pymol directory at the end of the
> sys.path rather than the beginning may be good enough.
>
> If the parser.py in the pymol is actually needed, you might need to rename
> its internal references to some other name, like pymolparser.
>
> HTH,
> DaveA
>
>

Thank you. Your second suggestion really helped.

To use pymol and numpy together, I now do the following:

To ~/.bashrc add:
PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
export PYMOL_PATH

Then I can do the following in python:

 import numpy
 numpy.save('123',numpy.array([1,2,3]))
 numpy.load('123.npy')
   array([1, 2, 3])
 import sys
 sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
 import pymol
 pymol.finish_launching()
 pymol.importing.load("/path/to/file.pdb")

Thanks,
Jeremiah
-- 
http://mail.python.org/mailman/listinfo/python-list