Re: Making a shorter shebang

2006-10-14 Thread Jerry
/usr/bin/env just searches your PATH variable to find it, but it does
so in order.  So, if you want it to find your python instead of a
system provided one, just alter your PATH variable and put
/home/my_username/python2.5 in front of everything else.

example in .profile:

PATH=/home//python2.5:$PATH
export PATH

--
Jerry

On Oct 14, 10:37 am, "veracon" <[EMAIL PROTECTED]> wrote:
> Long story short, in order to use Python 2.5, I've compiled it in my
> own account on my hosting. It works fantastic as
> /home/my_username/python2.5, but the shebang is a bit long. Is there a
> way to shorten it (environment variables?) or, even better, make
> /usr/bin/env python point to it?
> 
> Thanks in advance!

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


Re: Looking for assignement operator

2006-10-17 Thread Jerry


On Oct 17, 8:50 am, Alexander Eisenhuth <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> is there a assignement operator, that i can overwrite?
>
> class MyInt:
> def __init__(self, val):
> assert(isinstance(val, int))
> self._val = val
>
> a = MyInt(10)
>
> # Here i need to overwrite the assignement operator
> a = 12
>
> Thanks
> Alexander

I believe the property function is what you are looking for.  e.g.

class MyClass:
def __init__(self, val):
self.setval(val)

def getval(self):
return self._val

def setval(self, val):
assert(isinstance(val, int))
self._val = val

    _val = property(self.getval, self.setval)

--
Jerry

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


Re: Format a number as currency! I can't find any help on this simple problem.

2006-10-17 Thread Jerry
Replace the conv function call with locale.localeconv.

--
Jerry

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


Re: How to invoke ipython in Mac OS X?

2006-10-17 Thread Jerry
Did you install it with the --install-scripts command line option?  If
you did, then there will be a ipython script located in the
$INSTALL_SCRIPTS/bin directory.  If you didn't, then I think the
default location is /usr/lib/python or something like that.

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


Re: Looking for assignement operator

2006-10-17 Thread Jerry
> class MyClass:Descriptors don't work fine with old-style classes.
Interesting, I have used this construct before in Python 2.4.3 and not
run into the recursion problem you talk about.  Also, it has worked
fine for me.  Perhaps you can post a link to your source so that I
could study it and understand what circumstances my solution works and
what the recommended construct actually is.

> May I kindly suggest that you learn more about properties and test your
> code before posting ?-)
I did test this on Python 2.4.3 in Mac OS X 10.4 and it worked fine.

--
Jerry

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


Re: making a valid file name...

2006-10-17 Thread Jerry
I would suggest something like string.maketrans
http://docs.python.org/lib/node41.html.  I don't remember exactly how
it works, but I think it's something like

>>> invalid_chars = "abc"
>>> replace_chars = "123"
>>> char_map = string.maketrans(invalid_chars, replace_chars)
>>> filename = "abc123.txt"
>>> filename.translate(charmap)
'123123.txt'

--
Jerry

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


Re: Looking for assignement operator

2006-10-17 Thread Jerry
Okay, very well, then I put a couple of extra 'self' identifiers in
there when I hand-copied the code over.  That would be my mistake for
letting my fingers do the walking and forgetting my brain.  Is there
anything else wrong with my code?

--
Jerry

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


Re: external file closed

2006-10-17 Thread Jerry
On Oct 17, 12:43 pm, "kilnhead" <[EMAIL PROTECTED]> wrote:
> I am opening a file using os.start('myfile.pdf') from python. How can I
> know when the user has closed the file so I can delete it? Thanks.

I assume you mean os.startfile.  There is no way to do this directly.
os.startfile simply hands off the call to the OS and doesn't provide
anything to track anything after that.  Since you won't know what
program handled the file association, you couldn't watch for an
instance of that to start up and detect when it exits.  Even if you
could, it wouldn't be reliable as in the case of PDF's and Adobe
Acrobat Reader, the user could close the document, but not the
application, so your script would never delete the file in question.

If anyone can think of a way to do this, it would be interesting to see
how it's done.

--
Jerry

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


Decorators and how they relate to Python - A little insight please!

2006-10-19 Thread Jerry
I have just started to do some semi-serious programming (not one-off
specialized scripts) and am loving Python.  I just seem to get most of
the concepts, the structure, and the classes (something I struggled
with before in other languages).  I've seen many concepts on the web
(i.e. stacks, queues, linked lists) and can usually understand them
pretty well (event if I don't always know when to use them).  Now I've
come accross decorators and even though I've read the PEP and a little
in the documentation, I just don't get what they are or what problem
they are trying to solve.  Can anyone please point me to a general
discussion of decorators (preferrably explained with Python)?

Thanks,
Jerry

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


Re: Decorators and how they relate to Python - A little insight please!

2006-10-20 Thread Jerry
Thanks to everyone that resonded.  I will have to spend some time
reading the information that you've provided.

To Fredrik, unfortunately yes.  I saw the examples, but couldn't get my
head wrapped around their purpose.  Perhaps it's due to the fact that
my only experience with programming is PHP, Perl and Python and to my
knowledge only Python supports decorators (though it could be that I
just didn't encounter them until I came across Python).

--
Jerry

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


Re: I like python.

2006-10-20 Thread Jerry
On Oct 20, 2:59 am, Fidel <[EMAIL PROTECTED]> wrote:
> Could someone please tell me what I need to put into a python script
> to not have a window come up however briefly? Like when I double click
> on the script, it will do it's job but won't open a command window
> then close it.. I hope that explains what I'm looking for.  If I see
> the line I can figure out by syntax where it should go. I'm really
> good at learning the gist of languages by syntax.  Thank you all for
> your time

Are you running any external commands by using os.system() or
os.exec()?  If you are running a program that is a console program
(i.e. copy, move, del, etc...) then it will open up a command window to
run it.  If that is the case, then you can try using the os.popen()
utility instead.

--
Jerry

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


Re: I like python.

2006-10-24 Thread Jerry
Glad I could help.

--
Jerry

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


Re: How to find out the directory that the py file is in?

2006-10-24 Thread Jerry
import os
print os.path.dirname(os.path.abspath(__file__))

--
Jerry

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


Re: To remove some lines from a file

2006-10-25 Thread Jerry
Very inelegant, but you get the idea:

counter = 0

f = open("test.txt")
for line in f.readlines():
if line[0] != "$" and counter < 2:
counter += 1
continue
else:
    print line,

--
Jerry

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


Re: py2exe questions

2006-11-04 Thread Jerry
The McMillan (sp?) Python Installer has recently been resurrected as
well, though now, it is just called PyInstaller and can be found at
http://pyinstaller.python-hosting.com/

It allows you to create a one file distributable without the need to go
back to Python2.3.

Despite what everyone is saying though, I believe that any and all
solutions will require that the byte-code be extracted to some
directory before being run.  It's not as though you are REALLY
compiling the language to native code.  It's just a bootstrap around
the Python interpreter and your code plus any modules that it needs to
run.

--
Jerry

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


Re: adding python scripting to my application

2006-11-06 Thread Jerry
I am not a Python guru by any means, but I believe that when an
application says that you can "script" their application with Python,
it means that you can actually write Python code to interact with the
application.  Embedding may be the same thing.  Extending (as I read
it) involves writing portions of your program in Python and have do the
logic portions.

If you would like to allow users to write small scripts that interact
with your program and control it (a la VBScript or AppleScript), then I
believe embedding Python in your program is what you want.

If you would like Python to run various parts of your program in order
to make some portions easier to write/manage/whatever, then you want to
"extend" your program using Python.

The key difference being that you aren't providing a way for someone
else to interact with your program using Python if you are extending.

Again, I am not a guru and a read through the docs on python.org would
probably be the best place to get sound technical advice on these
subjects.

--
Jerry

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


Re: Algorithm for Labels like in Gmail

2006-06-10 Thread Jerry
I  would probably go with an SQLite database to store your information.
 You can have the contacts listed in a table with unique ids, then a
table of labels.  Finally, create a table that links one or more labels
with each contact.  Then you can just keep adding more labels.

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


Re: What's wrong in this HTML Source file of a Bank

2006-06-13 Thread Jerry
This really isn't the place to ask what is wrong with code that isn't
Python, especially of someone else's website.  There is absolutely no
way for us to tell what is happening on the server side.  You should
contact the maintainer of the site and let them know you are having
problems.

--
Jerry

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


telnetlib thread-safe?

2006-08-24 Thread Jerry
Can anyone tell me if the telnetlib module is thread-safe?  I've done
some looking, but don't know, and I don't know how to tell from reading
the module code.

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


Re: telnetlib thread-safe?

2006-08-24 Thread Jerry
Fredrik Lundh wrote:
> define thread-safe.  how do you plan to use it?

I would like to write a program that spawns ~10 threads.  Each thread
would get a host to connect to from a Queue object and run then do it's
thing (i.e. connecting to the host, running some commands, returning
back a success or fail based on the results).

I just want to make sure that telnetlib is safe for this.

--
Jerry

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


Re: telnetlib thread-safe?

2006-08-25 Thread Jerry
Great, thanks for the info.

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


wxPython and Py2exe crashes in "window" mode but not in "console" mode

2006-08-25 Thread Jerry
I have created an application using wxPython and compiled it using
py2exe.  When I put

setup(console=['myscript.py'])

in my setup.py file, the resulting application runs just fine.  But
when I change it to

setup(windows=['myscript.py'])

The application crashes without any indication of what happened.
During this particular point in the application it calls a
gethostbyaddr and gethostbyname and does a spawnl to another
application.  When I use Tkinter, this does not happen.  I've searched
around Google and the py2exe and wxPython sites and haven't found
anything that seems to relate to this.

Details:
All are binary distributions for Windows running on Windows XP SP2
ActivePython 2.4.3 Build 12
wxPython 2.6.3.3 (ansi) for Python 2.4
py2exe 0.6.5

Any ideas?

Thanks in advance.

--
Jerry

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


Re: wxPython and Py2exe crashes in "window" mode but not in "console" mode

2006-08-28 Thread Jerry
jean-michel, I'm at work at the moment and can't post with attachments.
 I will do so once I get home.

jean-michel bain-cornu wrote:
> I'd like to reproduce your crash, could you post a sample ?

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


Re: wxPython and Py2exe crashes in "window" mode but not in "console" mode

2006-08-28 Thread Jerry
http://www.heiselman.com/MultiSSH.zip

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


Re: Automation and scheduling of FrontPage publishing using Python

2007-09-01 Thread Jerry
andrew,

I would try looking into Windows automation with Python.
http://www.google.com/search?q=windows+automation+python should get
you started.  The winGuiAuto package may help you out as it is like
have a human click and move throughout the interface.  The only
downside is that there is no recorder to help you build the script, so
I would try to do as much in VBA as you can (does FrontPage even
support VBA?) and then just write your python script to get through
the program enough to execute the macro.

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


Re: newbie - returned values from cscript.exe

2007-01-24 Thread Jerry
I would probably start with a look at popen.  With it you can make your
call to cscript and capture the output.  Then, you don't need to set
any environment variables.

On Jan 24, 1:26 pm, "Rich" <[EMAIL PROTECTED]> wrote:
> I am writing my first python script and I'm guessing this is something
> obvious but I can't find any examples of doing something like this.  I
> have a python script that is running a vbscript through cscript.exe.
> The vbscript looks up a server name, username, password etc and returns
> these values in a delimited list using wscript.echo.  I can assign
> these values to variables using a Windows batch files with the
> following code
>
> FOR /F "tokens=1-6" %%a in ('cscript /nologo GetServerAccessInfo.vbs"')
> do (
> SET DB_SERVER_NAME=%%a
> SET DB_NAME=%%b
> SET NMDBO_USERNAME=%%c
> SET NMDBO_PASSWORD=%%d
> SET SU_USERNAME=%%e
> SET SU_PASSWORD=%%f
>
> I can't figure out how to do the same thing using a python script to
> call this instead of a batch file.
>
> I am running the vbscript by using the following command
> os.system('cscript /nologo GetServerAccessInfo.vbs')

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


Re: How can i do this in Python?

2007-01-24 Thread Jerry
Well, the python interpreter has no equivalent to -n or -a in the perl
interpreter.  You'd have to implement it using an actual while loop and
because of the indention sensitivity in Python, I don't believe you can
do it on the command line.  (I may be very wrong here, but I've not
gotten it to work).

--
Jerry

On Jan 24, 10:25 pm, "NoName" <[EMAIL PROTECTED]> wrote:
> perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"
> file.txt
>
> -a autosplit mode with -n or -p (splits $_ into @F)
> -n assume "while (<>) { ... }" loop around program

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


Re: Hi, I'm new to python

2007-01-27 Thread Jerry
I would definitely suggest checking out the documentation at http://
www.python.org/doc/.  Also, you can check out the free book Dive into 
Python at http://www.diveintopython.org.  It provides a great overview 
starting at the very beginning.  I found it great and hope to buy it 
soon to support the author.

Python is considered a general-purpose language (so is Perl by the 
way.)  It can handle anything from processing text, to running as an 
application server (check out http://www.zope.com.)  You can also use 
pieces of it for web programming.  In fact, if you've heard of Ruby on 
Rails, then you can see a similar Python project called TurboGears at 
http://www.turbogears.com.  If you only need a web framework, then you 
can also check out Django (http://www.djangoproject.com) and many 
other projects designed for getting a web-based application up and 
running quickly.

Not to leave you with the impression that it's really only suited for 
web stuff, there is also Pygame (http://www.pygame.com), a library and 
bindings to SDL so you can write your own games.  I am currently 
learning Pygame with OpenGL and writing a simple clone of SpaceWars.

I've also written a Jabber bot in Python for use where I used to 
work.  You can use Python for systems automation as well.  I wrote a 
small applet that opened SSH connections to every server in a list and 
then sent all the text you typed into a single box to all servers at 
the same time.

I'm currently learning how to use Python with osascript to control 
applications in Mac OS X and have dabbled a little with the win32com 
stuff to have Python control some aspects of Windows.

As you can see, it's an extremely versatile language and is really 
only limited by your imagination.

There are some things that it doesn't do so well, but for the most 
part, those things have solutions.  For example, Python is typically 
slower than other languages when you must iterate over something many 
times.  For example, in game programming, to iterate over the entire 
list of objects in the world to update their positions or draw them.  
Many times things like this can be moved into C libraries to make then 
run faster.  I myself haven't had many problems with this at all.  In 
fact, none of my iteration code is in C for my game.

Well, that's enough rambling for me.  I've turned this post into a 
commercial for Python.  I hope that I've left you with enough ideas to 
get started in the language.

--
Jerry H

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


Re: Python editor recommendation.

2006-05-09 Thread Jerry
I have used Eclipse+PyDev in the past.  I don't use the debugger though
and don't find the outline all that useful, so now I just use the
PythonWin interface that comes with the ActiveState Python
distribution.

Another one that I've heard lots of people seem to like is Stani's
Python Editor (SPE).  You can find it at
http://stani.be/python/spe/blog/

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


freeze tool like perl2exe?

2006-05-22 Thread Jerry
I am looking for a freeze tool for Python that is similar to perl2exe
in that I can "compile" a script on one platform that is built for
another.  Basically, I would like to be able to build a Python script
for Solaris using my Windows workstation.  Is there any tool that fits
the bill?

Thanks,
Jerry

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


Re: freeze tool like perl2exe?

2006-05-23 Thread Jerry
I did look at cx_Freeze at one point in time, but the documentation on
their site is pretty sparse and doesn't actually mention being able to
build for a different platform.  I'll take another look.  Thanks.

--
Jerry

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


Re: How to open https Site and pass request?

2006-05-23 Thread Jerry
That depends on your OS.  In Windows, I believe you would have to
recompile Python from source.  On Linux, you could probably just get a
package.  From Debian, I know that it's python-ssl.  I'm sure most the
others would have one as well.

--
Jerry

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


Re: Python Programming Books?

2006-05-24 Thread Jerry
I think that Beginning Python: From Novice to Professional is a great
book for beginners.  It's probably a bit too simplistic for someone who
already understands the language or who has a decent background in
development.  I just borrowed it from my brother and while I consider
myself a pretty good developer (I know PHP, Perl, Shell Scripting,
VBScript, Visual Basic, and some C), I found that some of the things
that other books presented where more advanced and that they left me
missing some of the more basic concepts in Python (i.e. list
comprehension made simple).  After Beginning Python, a good book to go
to would be Dive Into Python which you can get free at
http://www.diveintopython.org.  The book covers much of the same
material that Beginning Python does, but has many more full fleged
examples to help solidify what you are doing.  I've also heard really
good things about Learning Python, but these other two books seem to
cover all of the same material.

After these, I plan on reading Game Programming with Python and the
Python Cookbook to round out my library.
I'll have to check out Python Essential Reference and I'll probably get
Mastering Regular Expressions (which I think is a must have for any
language even though it focuses on Perl).

--
Jerry

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


European python developers

2008-02-26 Thread jerry
Hi Python Enthusiasts,

I am hoping one or two members of this list might help me locate in Europe
to begin a small team of developers with a focus on python for the central
part of the server development. 

My personal first choice is Spain only because I like it, and will
eventually have Spanish as a second language, but I am very concerned about
finding people, especially considering costs. 

I have worked virtually with three people from Ukraine and Russia, and a
chap living in Germany all who appear to be talented and others have told me
about other countries such as Poland. 

The point is that I can't really afford to run around and experiment, so I
was hoping for some helpful comments or suggestions on how to research, or
where to look, or how to recruit.

If this has already been a topic of the list, I would appreciate any
pointers.

Thanks, Jerry

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


RE: European python developers

2008-02-26 Thread jerry
Hi Terry,

Thank you for taking the time to respond. I enjoyed 7 weeks in Barcelona two
springs ago, but I think I would pick a different city to live. Yes, I am
talking about relocating full or part-time for myself, but a small fulltime
location.

Thanks, Jerry
 
-Original Message-
From: Terry Jones [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 26, 2008 10:51 PM
To: [EMAIL PROTECTED]
Cc: python-list@python.org
Subject: Re: European python developers

Hi Jerry

> I am hoping one or two members of this list might help me locate in Europe

Do you mean you want to re-locate here or that you're trying to locate
(i.e., find) people already here?

> My personal first choice is Spain

I'm in Barcelona (but not looking for work!).  There are a couple of
companies around that I know of who use Python and quite a lot of
individual programmers.

> The point is that I can't really afford to run around and experiment, so I
> was hoping for some helpful comments or suggestions on how to research

I'm not sure what you're wanting to research. See first comment above.

Terry

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


Re: just one more question about the python challenge

2006-04-13 Thread Jerry
This one threw me for a loop as well.  I looked at that gfx file for a
whole day before I finally understood what was in it.  I only knew to
separate it into five piles because of the hint forums though.  I guess
I'm not intuitive enough.  :)

I too did this challenge without PIL.  Just remember that all files are
just bytes of data.  Hopefully, that idea with the rest of the hints
will help you along.

On a side note, level 13 was really fun.  No images at all (whew!) and
I got to learn something about Python AND the other technology used.

As for level 14 back to images.  I really didn't like this level
and it was the first time that I needed to find a solution.  Yes, I
cheated on this level.  I'm not proud of it.  But as it turns out, my
solution was correct, but I was going in the wrong direction.  I
figured as much from the hints in the forum, but when I reversed my
algorithm, it still ended up wrong.  I didn't realize that there were
four directions you could use to build the image.  I had only accounted
for two and both were not right. *sigh*

On to level 15.

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


Re: just one more question about the python challenge

2006-04-13 Thread Jerry
John,

If you are really frustrated with this one (like I was on 14), email me
off-list to get further hints.  I'm willing to help you out.

I wish that someone was around to help me work through some of these.
I really think they are more fun/helpful when you work on them with
another person so if you don't see something in the riddle, they just
might.  For me, this is more about learning python than about solving
the riddles.

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


Re: Kross - Start of a Unified Scripting Approach

2006-04-13 Thread Jerry
So, this would be like .Net or Mono, but for KOffice?  Kind of like
AppleScript then?

Sorry, just starting to learn about some of this stuff (CLI, CLR, CIL,
etc...) and am interested in understanding better.

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


Re: Kross - Start of a Unified Scripting Approach

2006-04-14 Thread Jerry
Awesome, thanks for the explaination.  It was very informative.

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


Re: python backup script

2013-05-06 Thread Jerry Hill
On Mon, May 6, 2013 at 3:01 PM, MMZ  wrote:

> I am trying to backup database on CentOS linux server,I'm getting error
> when running the following script. anyone can help?
>
> Traceback (most recent call last):
>   File "./backup.py", line 8, in ?
> username = config.get('client', 'mmz')
>   File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> raise NoSectionError(section)
>

​I've never used ConfigParser, but that ​

​error message looks pretty simple to interpret.  You've set up a
ConfigParser object, told it to read in ~/my.cnf, the asked for the value
of section 'client', option 'mmz'.  The error indicates that your config
files doesn't have a section named 'client'.

What is the content of your ~/my.cnf file?

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-23 Thread Jerry Hill
On Thu, May 23, 2013 at 6:20 PM, Carlos Nepomuceno <
carlosnepomuc...@outlook.com> wrote:

> Can str.format() do the following?
>
> f = '%d %d %d'
> v = '1,2,3'
> print f % eval(v)
>

​Sure:

Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]
on win32
>>> f = "{} {} {}"
>>> v = "1,2,3"
>>> print(f.format(*eval(v)))
1 2 3
>>>

The * unpacks the tuple returned from eval(), so that you get 3 separate
parameters passed to format(), instead of the single tuple.​

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


Re: detect key conflict in a JSON file

2013-05-29 Thread Jerry Hill
On Wed, May 29, 2013 at 1:10 PM, Chris Rebert  wrote:

> On Wed, May 29, 2013 at 4:16 AM, Jabba Laci  wrote:
> > I have a growing JSON file that I edit manually and it might happen
> > that I repeat a key. If this happens, I would like to get notified.
> > Currently the value of the second key silently overwrites the value of
> > the first.
>
> You can pass an appropriate object_pairs_hook function to json.load():
> http://docs.python.org/2/library/json.html#repeated-names-within-an-object
> http://docs.python.org/2/library/json.html#json.load
>

​That makes it pretty easy to provide any validation you might like to your
JSON data. Here's a quick example that raises ValueError on duplicate keys,
since the docs didn't have any examples.

Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]
on win32

​>>> s = '{"x": 1, "x": 2, "x": 3}'
>>> def json_checker(seq):
d = {}
for key, value in seq:
if key in d:
raise ValueError("Duplicate key %r in json document" % key)
else:
d[key]=value
return d

>>> json.loads(s, object_pairs_hook=json_checker)
Traceback (most recent call last):
  File "", line 1, in 
json.loads(s, object_pairs_hook=checker)
  File "C:\Python32\lib\json\__init__.py", line 320, in loads
return cls(**kw).decode(s)
  File "C:\Python32\lib\json\decoder.py", line 351, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python32\lib\json\decoder.py", line 367, in raw_decode
obj, end = self.scan_once(s, idx)
  File "", line 5, in json_checker
raise ValueError("Duplicate key %r in json document" % key)
ValueError: Duplicate key 'x' in json document

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


Re: Is this PEP-able? fwhile

2013-06-26 Thread Jerry Peters
Dennis Lee Bieber  wrote:
> On Mon, 24 Jun 2013 19:01:11 -0700 (PDT), rusi 
> declaimed the following:
> 
>>On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote:
>>> On Tue, Jun 25, 2013 at 5:52 AM,  <> wrote:
>>> 
>>> > (NOTE:  Many people are being taught to avoid 'break' and 'continue' at 
>>> > all
>>> > costs...
>>> 
>>> Why? Why on earth should break/continue be avoided?
>>
>>Because breaks and continues are just goto-in-disguise?
>>
>Because GOTO is a wild-card, capable of redirecting to anywhere;
> whereas break can only go to the exit of the loop (and in languages with
> labeled loops, possibly the exit of an outermost loop -- cf: Ada), and
> continue can only go to the next iteration of the loop (hmmm, does any
> language have a continue that can go to the next iteration of an outer
> loop?)

Bash:
continue: continue [n]
Resume for, while, or until loops.

Resumes the next iteration of the enclosing FOR, WHILE or
UNTIL loop.
If N is specified, resumes the Nth enclosing loop.

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


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Jerry Hill
On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k  wrote:
> Is there a way to extract out of some environmental variable the Geo
> location of the user being the city the user visits out website from?
>
> Perhaps by utilizing his originated ip address?

No, you'd need to take the originating IP address and look it up in a
geolocation database or submit it to a geolocation service and get the
response back from them.  It's not stored in any environment
variables.

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


Re: PyGLet, 2to3...?

2013-07-26 Thread Jerry Hill
On Thu, Jul 25, 2013 at 7:49 PM, John Ladasky
 wrote:
> ===
>
> john@john:~/Desktop/pyglet-1.2alpha1$ sudo python3 setup.py install
>
> [sudo] password for john:
>
> running install
> running build
> running build_py
> running install_lib
> running install_egg_info
> Removing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
> Writing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info

Pyglet was installed to /usr/local/lib/python3.3/dist-packages ...

> john@john:~/Desktop/pyglet-1.2alpha1$ python3
>
> Python 3.3.1 (default, Apr 17 2013, 22:30:32)
> [GCC 4.7.3] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import pyglet
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "./pyglet/__init__.py", line 276
> print '[%d] %s%s %s' % (thread, indent, name, location)
>^
> SyntaxError: invalid syntax

... But here, the error message is talking about ./pyglet/__init__.py.
 I think you're accidentally importing the pyglet package from the
local directory instead of from the proper location in dist-packages.
Try changing back to your home directory and trying this again.  I
think you're picking up the code from
~/Desktop/pyglet-1.2alpha1/pyglet instead of from
/usr/local/lib/python3.3/dist-packages.

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


Re: Python and Facebook

2012-06-24 Thread Jerry Rocteur
Hi,

I posted this mail on Friday and received no replies..

I'm curious..

Is it because

1) Python is not the language to use for Facebook, use Javascript or XXX ??
instead ? Please tell.
2) I've missed the point and this is very well documented so RTFM (I
couldn't find it)
3) You guys don't use Facebook, you have a life ..

Can someone please point me in the right direction..

Thanks in advance,

Jerry

On Fri, Jun 22, 2012 at 4:28 PM, Jerry Rocteur wrote:

> Hi,
>
> I've done a bit of searching on this but I can find nothing really up to
> date and a lot of conflicting information about using Python and Facebook.
>
> I'd like to automate some tasks in Facebook, for example I'd like to
> connect to a group I'm admin of and take a copy of all photos, a list of
> all members and member's info, I'd also like to connect every day and take
> all the days posts and save them as it is so hard to find back things in
> groups.
>
> I'd like to use Python to do this but I can't find what is the best module
> to do this or even how to go about doing it.
>
> Can someone please put me in the right direction.
>
> Thanks in advance,
>
> --
> Jerry Rocteur
> je...@rocteur.com
> Contact me: Google Talk/jerry.roct...@gmail.com, Skype/rocteur
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and Facebook

2012-06-25 Thread Jerry Rocteur
Hi,

I've done a bit of searching on this but I can find nothing really up to
date and a lot of conflicting information about using Python and Facebook.

I'd like to automate some tasks in Facebook, for example I'd like to
connect to a group I'm admin of and take a copy of all photos, a list of
all members and member's info, I'd also like to connect every day and take
all the days posts and save them as it is so hard to find back things in
groups.

I'd like to use Python to do this but I can't find what is the best module
to do this or even how to go about doing it.

Can someone please put me in the right direction.

Thanks in advance,

--
Jerry Rocteur
je...@rocteur.com
Contact me: Google Talk/jerry.roct...@gmail.com, Skype/rocteur
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Facebook

2012-06-27 Thread Jerry Rocteur
>
>
> > > (Among our points are such diverse elements as... wrong Pythons, but
> whatever.)
> >
> > > There's no official Python-Facebook module (afaik!!), but a quick web
> > > search for 'python facebook' should get you to the couple that I saw,
> > > and possibly others. The next question is, do you trust any of them...
> > > Good luck with that one! :)
> >
> > > Chris Angelico
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> FWOW. I tried for about a week every Python Facebook module out there
> I could find (including that one), with Python 2.5 or 2.7, and for
> whatever reason was unsuccessful in uploading a photo and quit
> trying.  Frustrating.
>
>
That is sad to read..

When I see what TheSocialFixed does with Javascript in Facebook I think
I'll give Javascript it a go...

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


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Jerry Hill
On Fri, Jul 13, 2012 at 9:00 PM, Gelonida N  wrote:
> I tried the simplest approach (just printing the BEL character '\a' chr(7)
> to the console.

That's what I do when I want to send an audible alert to the user of a
console based program.  It's then up to the user's terminal to do
whatever the user wants. Printing a BEL character has the added
advantage that it plays nicely with programs that are run remotely
(through ssh sessions and the like).

Personally, I'm usually in a screen session, inside either an xterm or
over an ssh link, and have visual bells turned on so I can see the
alerts, even when they pop up in another screen.

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


Re: print(....,file=sys.stderr) buffered?

2012-08-13 Thread Jerry Hill
On Mon, Aug 13, 2012 at 11:16 AM, Helmut Jarausch  wrote:
> Now, when executing this, I always get
>
> +++ before calling foo
> --- after  calling foo
>>>> entering foo ...

Can you give us a piece of code we can run that produces this output
for you?  You gave us an outline in your original post, but it would
be useful to have a self contained example that you can say reliably
produces the unexpected output for you.

Also, what environment, OS, and exact python version is this?  Is the
code being run in an IDE of some sort?  Does the behavior change if
you call your code directly from the command line?

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


Re: How do I display unicode value stored in a string variable using ord()

2012-08-17 Thread Jerry Hill
On Fri, Aug 17, 2012 at 1:49 PM,   wrote:
> The character '…', Unicode name 'HORIZONTAL ELLIPSIS',
> is one of these characters existing in the cp1252, mac-roman
> coding schemes and not in iso-8859-1 (latin-1) and obviously
> not in ascii. It causes Py3.3 to work a few 100% slower
> than Py<3.3 versions due to the flexible string representation
> (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%).
>
>>>> '…'.encode('cp1252')
> b'\x85'
>>>> '…'.encode('mac-roman')
> b'\xc9'
>>>> '…'.encode('iso-8859-1') # latin-1
> Traceback (most recent call last):
>   File "", line 1, in 
> UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026'
> in position 0: ordinal not in range(256)
>
> If one could neglect this (typographically important) glyph, what
> to say about the characters of the European scripts (languages)
> present in cp1252 or in mac-roman but not in latin-1 (eg. the
> French script/language)?

So... python should change the longstanding definition of the latin-1
character set?  This isn't some sort of python limitation, it's just
the reality of legacy encodings that actually exist in the real world.


> Very nice. Python 2 was built for ascii user, now Python 3 is
> *optimized* for, let say, ascii user!
>
> The future is bright for Python. French users are better
> served with Apple or MS products, simply because these
> corporates know you can not write French with iso-8859-1.
>
> PS When "TeX" moved from the ascii encoding to iso-8859-1
> and the so called Cork encoding, "they" know this and provided
> all the complementary packages to circumvent this. It was
> in 199? (Python was not even born).
>
> Ditto for the foundries (Adobe, Linotype, ...)


I don't understand what any of this has to do with Python.  Just
output your text in UTF-8 like any civilized person in the 21st
century, and none of that is a problem at all.  Python make that easy.
 It also makes it easy to interoperate with older encodings if you
have to.

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


Re: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS

2012-08-19 Thread Jerry Hill
On Sun, Aug 19, 2012 at 6:27 PM, coldfire  wrote:
> Also I have no idea how to deploy a python script online.
> I have done that on my local PC using Apache server and cgi but it Works fine.
> Whats this all called? as far as I have searched its Web Framework but I dont 
> wont to develop  a website Just a Server which can run my scripts at specific 
> time and send me email if an error occurs.
> I use Python And i am not getting any lead.

If you want to host web pages, like your're doing on your local pc
with Apache and cgi, then you need an account with a web server, and a
way to deploy your scripts and other content.  This is often known as
a 'web hosting service'[1].  The exact capabilities and restrictions
will vary from provider to provider.

If you just want an alway-on, internet accessable place to store and
run your python scripts, you may be interested in a 'shell
account'[2], or if you need more control over the environment, a
'virtual private server'[3].

That may give you a few terms to google, and see what kind of service you need.

1 http://en.wikipedia.org/wiki/Shell_account
2 http://en.wikipedia.org/wiki/Web_host
3 http://en.wikipedia.org/wiki/Virtual_private_server

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


Re: Why doesn't Python remember the initial directory?

2012-08-19 Thread Jerry Hill
On Sun, Aug 19, 2012 at 9:57 PM, kj  wrote:
> By now I have learned to expect that 99.99% of Python programmers
> will find that there's nothing wrong with behavior like the one
> described above, that it is in fact exactly As It Should Be, because,
> you see, since Python is the epitome of perfection, it follows
> inexorably that any flaw or shortcoming one may *perceive* in Python
> is only an *illusion*: the flaw or shortcoming is really in the
> benighted programmer, for having stupid ideas about programming
> (i.e. any idea that may entail that Python is not *gasp* perfect).
> Pardon my cynicism, but the general vibe from the replies I've
> gotten to my post (i.e. "if Python ain't got it, it means you don't
> need it") is entirely in line with these expectations.

Since you have no respect for the people you're writing to, why
bother?  I know I certainly have no desire to spend any time at all on
your problem when you say things like that.  Perhaps you're looking
for for the argument clinic instead?

http://www.youtube.com/watch?v=RDjCqjzbvJY

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


Re: python 6 compilation failure on RHEL

2012-08-21 Thread Jerry Hill
On Tue, Aug 21, 2012 at 12:34 AM, John Nagle  wrote:
> After a thread of clueless replies, it's clear that nobody
> responding actually read the build log.  Here's the problem:

The very first reply, Emile's, pointed out that these were optional
modules, and that python did, in fact build successfully.

>   Failed to find the necessary bits to build these modules:
> bsddb185
> dl
> imageop
> sunaudiodev
>
> What's wrong is that the Python 2.6 build script is looking for
> some antiquated packages that aren't in a current RHEL.  Those
> need to be turned off.

They don't need to be turned off.  They can either be ignored (because
they aren't needed, and did not cause the build to fail), or the
development libraries for those pieces can be installed and python
recompiled.

The rest of the thread has been commenting on the OP's choice of
python version and operating system.  That's not exactly on topic, but
the original question was answered in the very first response.

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


Re: writelines puzzle

2012-08-22 Thread Jerry Hill
On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing)
 wrote:
> Much to my surprise, when I looked at the output file, it only contained 160 
> characters.  Catting produces:
>
> StraylightPro:Logs wrw$ cat RTT_monitor.dat
> 2354[ 734716.72185185  734716.72233796  734716.72445602 ...,  734737.4440162
>   734737.45097222  734737.45766204][ 240.28.5   73.3 ...,   28.4   27.4   
> 26.4]

If that's the full output, then my guess is that x_dates and y_rtt are
not actual python lists.  I bet they are, in fact, numpy arrays and
that the string representation of those arrays (what you're getting
from str(x_dates), etc) include the '...' in the middle instead of the
full contents.

Am I close?

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


Re: Objects in Python

2012-08-23 Thread Jerry Hill
On Thu, Aug 23, 2012 at 4:59 AM, Jussi Piitulainen
 wrote:
> I don't get it either. To me the python-has-no-variables campaigners
> seem confused. As far as I can see, Python can be seen in terms of
> variables bound to (locations containing) values perfectly well, in a
> way that should be quite familiar to people who come from Java (or
> Lisp, Scheme like me).

Personally, when I was learning python I found the idea of python
having names and values (rather than variables and references) to
clear up a lot of my misconceptions of the python object model.  I
think it's done the same for other people too, especially those who
come from the C world, where a variable is a named and typed location
in memory.

Perhaps those that come from the Java and Lisp world don't find the
name/value paradigm as helpful.  Still, it seems silly to excoriate
people on the list for trying to explain python fundamentals in
several different ways.  Sometimes explaining the same idea in
different words helps people understand the concept better.

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


Re: Accessing dll

2012-09-06 Thread Jerry Hill
On Thu, Sep 6, 2012 at 11:07 AM, Helpful person  wrote:
> I am a complete novice to Python.  I wish to access a dll that has
> been written to be compatible with C and VB6.  I have been told that
> after running Python I should enter  "from ctypes import *" which
> allows Python to recognize the dll structure.  I have placed the dll
> into my active directory (if that's the correct word, one on my path)
> for simplification.
>
> I tried:   "import name.dll" but this just gave me an error telling me
> that there was no such module.
>
> Can someone please help?

You should start by reading the ctypes documentation, here:
http://docs.python.org/library/ctypes.html .  It has a lot of examples
that ought to get you started.

When you run into more specific problems, you're going to have to
provide a lot more information before we can help you, including the
specific documentation of the DLL you're trying to wrap, your
platform, and python version.  If you are not permitted to share those
things, we may not be able to give you much help.  Ctypes is very
specific to the actual library you are accessing, and requires that
you understand the requirements of the underlying DLL.

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


Re: Accessing dll

2012-09-06 Thread Jerry Hill
On Thu, Sep 6, 2012 at 12:46 PM, Helpful person  wrote:
> The reference might help if I could get Python to recognize the dll as
> a module.

That's never going to happen.  It's a DLL, not a python module.  I
think the documentation lays that out pretty explicitly.  Have you
experimented with the very first bit of example code in the
documentation?  What do you get if you do the following at the
interactive interpreter?

>>> from ctypes import *
>>> print windll.


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


Re: How to limit CPU usage in Python

2012-09-20 Thread Jerry Hill
On Thu, Sep 20, 2012 at 11:12 AM, Rolando Cañer Roblejo
 wrote:
> Hi all,
>
> Is it possible for me to put a limit in the amount of processor usage (%
> CPU) that my current python script is using? Is there any module useful for
> this task? I saw Resource module but I think it is not the module I am
> looking for. Some people recommend to use nice and cpulimit unix tools, but
> those are external to python and I prefer a python solution. I am working
> with Linux (Ubuntu 10.04).

Maximum percentage of CPU used isn't normally something you control.
The only way I know of to do it involves having another process
monitor the thing you want to control and sending signals to stop and
start it (e.g., http://cpulimit.sourceforge.net/).

Typically, you instead want to control the priority (so that higher
priority apps can easily take more CPU time).  That's what nice is for
(http://docs.python.org/library/os.html#os.nice).  If you want to
limit a process in the same way that ulimit does, then the resources
module is what you want
(http://docs.python.org/library/resource.html#resource.setrlimit).

Is there a particular reason that you'd rather have your CPU sitting
idle, rather than continuing with whatever code is waiting to be run?
I'm having a hard time understanding what problem you might be having
that some combination of setting the nice level and imposing resource
limits won't handle.

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


Re: How to apply the user's HTML environment in a Python programme?

2012-09-21 Thread Jerry Hill
On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma  wrote:
> Thanks, Joel, yes, but as far as I'm aware these would all require the Python 
> programme to have the user's username and password (or "credentials"), which 
> I wanted to avoid.

No matter what you do, your web service is going to have to
authenticate with the remote web site.  The details of that
authentication are going to vary with each remote web site you want to
connect to.

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


Re: How to limit CPU usage in Python

2012-09-27 Thread Jerry Hill
On Thu, Sep 27, 2012 at 12:58 PM, Prasad, Ramit
 wrote:
> On *nix you should just set the appropriate nice-ness and then
> let the OS handle CPU scheduling. Not sure what you would do
> for Windows--I assume OS X is the same as *nix for this context.

On windows, you can also set the priority of a process, though it's a
little different from the *nix niceness level.  See
http://code.activestate.com/recipes/496767/ for a recipe using
pywin32.  I believe the psutil module handles this too, but I don't
think it manages to abstract away the platform differences.

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


Re: Python source code easy to hack?

2012-09-28 Thread Jerry Hill
On Fri, Sep 28, 2012 at 10:18 AM,   wrote:
> Python bytecode is not easier to hack than Java or .NET bytecodes.

This is true, but both java and .net are also relatively easy to decompile.

In general though, why does it matter?  What are you trying to protect
yourself against?  If you're including secrets in your code like
encryption keys or bank account numbers, there's no way to keep them
out of the hands of a determined attacker that has access to your
file, no matter what language it may be written in.

If you must keep anyone from ever seeing how your code works, the only
way to do that is to keep all the sensitive bits running on a machine
that you control.  Typically, you would do that by distributing a
client portion of your application, and also running a web service.
Then you can have your client connect to the web service, request that
the sensitive calculations, or money transfer, or whatever, be done on
the server, and just pass back the results.

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


Re: get google scholar using python

2012-10-01 Thread Jerry Hill
On Mon, Oct 1, 2012 at 1:28 PM, রুদ্র ব্যাণার্জী  wrote:
> So, If I manage to use the User-Agent as shown by you, will I still
> violating the google EULA?

Very likely, yes.  The overall Google Terms of Services
(http://www.google.com/intl/en/policies/terms/) say "Don’t misuse our
Services. For example, don’t interfere with our Services or try to
access them using a method other than the interface and the
instructions that we provide."

The only method that Google appears to allow for accessing Scholar is
via the web interface, and they explicitly block web scraping through
that interface, as you discovered.  It's true that you can get around
their block, but I believe that doing so violates the terms of
service.

Google does not appear to offer an API to access Scholar
programatically, nor do I see a more specific EULA or TOS for the
Scholar service beyond that general TOS document.

That said, I am not a lawyer.  If you want legal advice, you'll need
to pay a lawyer for that advice.

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


Re: string contains and special characters

2012-10-09 Thread Jerry Hill
On Tue, Oct 9, 2012 at 10:02 AM, loial  wrote:
> I am trying to match a string that containing the "<" and ">" characters, 
> using the string contains function, but it never seems to find the lines 
> containing the string
>
> e.g if mystring.contains("") :
>
> Do I need to escape the characters...and if so how?

Strings don't have a contains() method.  Assuming that mystring is
actually a string, you should be getting a very specific error,
telling you exactly what's wrong with your code (something like
AttributeError: 'str' object has no attribute 'contains').

If that isn't what you're seeing, you'll need to provide the full and
complete text of the error you are getting, and preferably enough of
your code that we can reproduce the issue and help you solve it.

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


Re: Is there a way to create kernel log messages via Python?

2012-10-16 Thread Jerry Peters
J  wrote:
> Hi...
> 
> I have a bit of code that does the following:
> 
> uses the syslog module to inject a LOG_INFO message into the syslog on
> my linux machine
> runs a suspend/resume cycle
> uses the syslog module to inkect a LOG_INFO message marking the end of test.
> 
> Then I parse everything between the start and stop markers for certain
> items that the Linux kernel logs during a suspend and resume cycle.
> 
> But my  "resume complete" timing is not as accurate as it could be.
> The problem with doing it this way is that while I can find definite
> kernel messages that mark various points in the suspend/resume cycle,
> the final message when the kernel is done resuming is NOT the point I
> actually want to mark.
> 
> Instead, the end point I want is the time of the ending marker itself,
> as this happens after certain other things are done such as resumption
> of networking services.
> 
> Here's the problem.  I can't just use syslog timestamps.  The reason
> is that the syslog timestamps are only indicative of when messages are
> written to syslog via syslogd.  The kernel timestamps are different.
> For example, the following bits of log are taken from the time the
> test starts until the end of the "going to sleep" kernel messages.
> First, note that there's a 5 second difference between the START
> marker and the first kernel message.  Next, look at the kernel
> timestamps.  The total real time to suspend starts at 421320.380947
> and ends at 421322.386355, around 2 seconds later, where the log
> messages themselves all state that the events occurred at the same
> time.
> 
> Oct 15 10:24:19 klaatu sleep_test: ---SLEEP TEST START 1350296656---
> Oct 15 10:25:24 klaatu kernel: [421320.380947] PM: Syncing filesystems ... 
> done.
> Oct 15 10:25:24 klaatu kernel: [421320.391282] PM: Preparing system
> for mem sleep
> [SNIP]
> Oct 15 10:25:24 klaatu kernel: [421322.282943] Broke affinity for irq 23
> Oct 15 10:25:24 klaatu kernel: [421322.386355] CPU 7 is now offline
> 
> So, what I REALLY want is to inject my start/stop markers into klogd
> rather than syslogd.  This will, I hope, give my markers kernel
> timestamps rather than syslog timestamps which are not as accurate.
> 
> So does anyone know of a way to do this?  Unfortunately, I've tried
> some searching but google doesn't like the term klog, and most of the
> hits involved injecting code or other things that are not related at
> all.
> 
> Or, if there's a better way to get accurate timestamps, what would that be?


Take a look at /dev/kmsg, I *believe* it's the way various boot
logging programs inject application type messages into the kernel boot
up message stream.

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


Re: problem with usbtmc-communication

2012-12-11 Thread Jerry Hill
On Tue, Dec 11, 2012 at 1:58 AM, Jean Dubois  wrote:
>
> I found examples in the usbtmc kernel driver documentation (the
> examples there are given in C):
> http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&lc=dut

Thanks for that link.  I think it explains how the driver works pretty
well.  I haven't done any work with devices like this, but I see a few
things in those docs that might help.

In their example code, they open the device with: open(“/dev/usbtmc1”,O_RDWR);

That's not exactly the same as what you've been doing.  I would try
opening the file this way in python:
usb_device = open('/dev/usbtmc1', 'w+', buffering=0)

That truncates the file after it opening it, and disables any
buffering that might be going on.

Then, I would try writing to the device with usb_device.write() and
usb_device.read().  read() attempts to read to end-of-file, and based
on the docs, the driver will work okay that way.  Doing that, along
with turning off buffering when you open the file, should eliminate
any issues with the driver failing to emit newlines someplace.

Personally, I would probably try playing with the device from python's
interactive interpreter.  I think that could shed a lot of light on
the behavior you're seeing.

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


Re: Python parser problem

2012-12-12 Thread Jerry Hill
On Wed, Dec 12, 2012 at 2:10 PM, RCU  wrote:
> With this occasion I would like to ask also what are the limits of the
> Python 2.x and 3.x parser. Where can I find what are the limits on the
> size/lines of the parsed script?

The Python Language Reference is probably what you're looking for:
http://docs.python.org/2/reference/index.html

See, particularly, section 2 about lexical analysis and possibly
section 9 for the grammar.  The short answer though, is that python
doesn't have any limits on the line length or the size of a script,
other than that execution will obviously fail if you run out of memory
while parsing or compiling the script.

PEP 8 (http://www.python.org/dev/peps/pep-0008/) is the Python style
guide, and it does have some recommendations about line length
(http://www.python.org/dev/peps/pep-0008/#maximum-line-length).  That
document suggests a maximum length of 79 characters per line, and
that's probably what PythonTidy was trying to accomplish by splitting
your line.

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


Re: Else statement executing when it shouldnt

2013-01-23 Thread Jerry Hill
On Wed, Jan 23, 2013 at 8:35 AM, Jussi Piitulainen
 wrote:
>> The feature isn't bad, it's just very, very badly named.
>
> I believe it would read better - much better - if it was "for/then"
> and "while/then" instead of "for/else" and "while/else".

That's always been my opinion too.  I'd remember how the construct
worked if it was for/then (and while/then).  Since seeing for/else
always makes my brain lock up for a few seconds when I'm reading code,
I don't bother using it.

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


Re: Maximum Likelihood Estimation

2013-02-01 Thread Jerry Hill
On Fri, Feb 1, 2013 at 1:59 PM, Michael Torrie  wrote:
> Most people on this list consider 8 dihedral to be a badly
> programmed bot.

For what it's worth, I think it's a very cleverly programmed bot.  It
usually makes just enough sense for me to wonder if there really is a
human being behind the keyboard.

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


Re: Parsing a serial stream too slowly

2012-01-23 Thread Jerry Hill
On Mon, Jan 23, 2012 at 4:48 PM, M.Pekala  wrote:

> Hello, I am having some trouble with a serial stream on a project I am
> When one sensor is running my python script grabs the data just fine,
> removes the formatting, and throws it into a text control box. However
> when 3 or more sensors are running, I get output like the following:
>
> Sensor 1: 373
> Sensor 2: 112$$M-160$G373
> Sensor 3: 763$$A892$
>
> I am fairly certain this means that my code is running too slow to
> catch all the '$' markers. Below is the snippet of code I believe is
> the cause of this problem...
>

That doesn't sound right.  Being too slow seems unlikely to produce the
wrong data...


def OnSerialRead(self, event):
>text = event.data
>self.sensorabuffer = self.sensorabuffer + text
>self.sensorbbuffer = self.sensorbbuffer + text
>self.sensorcbuffer = self.sensorcbuffer + text
>
>if sensoraenable:
>sensorresult = re.search(r'\$A.*\$.*', self.sensorabuffer )
>

Here, you search in sensorabuffer (which, by the way, would be much more
readable to me as sensor_a_buffer, as recommended by the PEP 8 style guide).



>if sensorbenable:
>sensorresult = re.search(r'\$A.*\$.*', self.sensorbenable)
>

here, you're not searching in the buffer, but in the enable flag.



>if sensorcenable:
>    sensorresult = re.search(r'\$A.*\$.*', self.sensorcenable)
>

And here too.

Does that fix the problem?

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


Re: windows and home path

2012-01-24 Thread Jerry Hill
On Tue, Jan 24, 2012 at 9:56 AM, Andrea Crotti
 wrote:
> Window never stops to surprise me, I've been banging my head since yesterday
> and only
> now I now what is the problem.
>
> So suppose I have something like
>
> from os import path
> print path.expanduser('~')
>
> If I run it from cmd.exe I get /Users/user, doing the same in an emacs
> eshell buffer I get
> /Users/user/AppData/Roaming.
>
> What sense does it make??
> Is there a way to get always the same variable from python somehow?

The os.path.exanduser() docs (
http://docs.python.org/library/os.path.html#os.path.expanduser ) say
that "On Windows, HOME and USERPROFILE will be used if set, otherwise
a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user
is handled by stripping the last directory component from the created
user path derived above."

So, my guess is that emacs is mangling your HOME environment variable.
 That appears to be confirmed by the emacs documentation here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables
.

At a guess, you do not have a system-wide HOME environment variable.
When you launch python from the command line, it uses either your
USERPROFILE setting, or is falling back to using HOMEDIRVE and
HOMEPATH.  When you launch emacs, it sees that HOME is not set, and
emacs helpfully sets it for you, to whatever path it thinks is
correct.  That would explain why you see different answers in
different environments.

Does that explain the behavior you're seeing?

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


Re: windows and home path

2012-01-24 Thread Jerry Hill
On Tue, Jan 24, 2012 at 11:05 AM, Jerry Hill  wrote:
> So, my guess is that emacs is mangling your HOME environment variable.
>  That appears to be confirmed by the emacs documentation here:
> http://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables

I know, it's bad form to follow up to my own email, but here's a more
concrete reference stating that emacs will set HOME  when emacs
starts: 
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html

"[Wherever Emacs finds your .emacs file], Emacs sets the value of the
HOME environment variable to point to it, and it will use that
location for other files and directories it normally creates in the
user's home directory. "

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


Re: windows and home path

2012-01-24 Thread Jerry Hill
On Tue, Jan 24, 2012 at 11:10 AM, Andrea Crotti
 wrote:
> Ah yes thanks for the explanation, on Python 2.7 on Linux I don't see
> the same doc, it might have been updated later..
> Anyway I just want to make sure that I get always the same path,
> not depending on the program.
>
> From a first look it seems that just using os.getenv('HOMEPATH') on
> windows might make the trick..

It would not do the trick on my windows XP workstation here.  Your
target environments may be different, of course.  From a general
command prompt (cmd.exe) on my work machine, here's what you would
have to work with:

HOMEDRIVE=H:
HOMEPATH=\
HOMESHARE=\\server\share\userdirectory
USERPROFILE=C:\Documents and Settings\username

There is no HOME set here.  So, what's the right home directory for me
on this PC?  Depending on your opinion of "right" you could end up
with three different answers:  "H:\", "\\server\share\userdirectory",
or "C:\Documents and Settings\username" all seem like valid candidates
to me.  Just going by HOMEPATH isn't going to be helpful if I were to
run your code though.

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


Re: search google with python

2012-01-25 Thread Jerry Hill
On Wed, Jan 25, 2012 at 5:36 AM, Tracubik  wrote:
> thanks a lot but it say it's deprecated, is there a replacement? Anyway
> it'll useful for me to study json, thanks :)

I don't believe Google is particularly supportive of allowing
third-parties (like us) to use their search infrastructure.  All of
the search-related APIs they used to provide are slowly going away and
not being replaced, as far as I can tell.

If you just need to search images (and not Google Image Search in
particular), Bing's API appears to be supported and not about to go
away.  ( http://msdn.microsoft.com/en-us/library/dd900818.aspx )

You could, in theory, make requests to Google just like a web browser
and parse the resulting HTML, but that tends to be fragile and prone
to break.  I believe it also violates Google's Terms of Service.

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


Re: object aware of others

2012-01-29 Thread Jerry Hill
On Sun, Jan 29, 2012 at 1:47 AM, Lee  wrote:

> I was afraid that a list/set/dictionary and alike is the answer, but,
> anyway, thanks everybody.
>
>
It doesn't seem too bad to keep track of the instances in the class object
using weak references (http://docs.python.org/py3k/library/weakref.html).
Here's an example that seems to do what you're asking using python 3.2, but
it should be pretty similar in python 2:

import weakref

class A:
_instances = set()
def __init__(self):
self.myname = 'IamA'
print('This is A')
self.__class__._instances.add(weakref.ref(self))
def foo(self):
print("foo")
def update(self):
for ref in self.__class__._instances:
obj = ref()
if obj is not None:
print("The only friends I've got are ", ref, obj.myname)


If you're creating lots of instances of A and deleting them, it would
probably be worth removing the old weakrefs from the _instances set instead
of just ignoring them when calling update().

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


Re: package extension problem

2012-02-13 Thread Jerry Hill
On Sun, Feb 12, 2012 at 1:46 PM, Fabrizio Pollastri wrote:

> Hello,
>
> I wish to extend the functionality of an existing python package by
> creating
> a new package that redefines the relevant classes of the old package. Each
> new class inherits the equivalent old class and adds new methods.
> ...

There is a way to solve this problem without redefining in the new package
> all the
> methods of the old package that return old classes?
>

The general answer is no.  If you want the methods of your subclass to
behave differently, in any way, from the same methods in the superclass,
then you must write new code that defines the behavior that you want.

Sometimes people write their classes so they automatically play nicely when
subclassed, and sometimes they don't.  In general, it's impossible to
always do the right thing when you don't know what particular behavior a
subclass might need to override, so a lot of times people don't bother to
write their classes to check for subclasses being passed in, etc.

Since you haven't actually shown us any code, that's about all I can tell
you.

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


Re: Beware, my computer was infected.

2012-02-20 Thread Jerry Zhang
By the way, i like 1.exe, can i have it?

在 2012年2月18日 上午6:01,Jugurtha Hadjar 写道:

> On 16/02/2012 01:34, Jugurtha Hadjar wrote:
>
>> Hello gentlemen,
>>
>> I'm writing these words to give you a heads up. My computer has recently
>> been infected with "1.exe", and I am doing what I can to contain it. It
>> spreads via mail and I fear it will send SPAM to lists I am subscribed to.
>>
>> If you receive weird mails from my address, thank you to report it to me.
>> I will not send you an executable, so if you receive one from me, please do
>> not open it and it would be nice to report it.
>>
>> I will  send an e-mail to this list once I think it is no longer in the
>> system.
>>
>> Thank you all.
>>
>>
> Everything is under control.
>
>
>
> --
> ~Jugurtha Hadjar,
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just curious: why is /usr/bin/python not a symlink?

2012-02-23 Thread Jerry Hill
On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster  wrote:
> $ cd /usr/bin
> $ ls -l python*
> -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python
> lrwxrwxrwx 1 root root    6 Oct 29 19:34 python2 -> python
> -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7
> $ diff -s  python python2.7
> Files python and python2.7 are identical
> $
>
> I'm just curious: Why two identical files rather than a symlink?

It's not two files, it's a hardlink.  You can confirm by running ls
-li python* and comparing the inode numbers.

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


Re: Just curious: why is /usr/bin/python not a symlink?

2012-02-23 Thread Jerry Hill
On Thu, Feb 23, 2012 at 2:34 PM, HoneyMonster  wrote:
> On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote:
>> It's not two files, it's a hardlink.  You can confirm by running ls -li
>> python* and comparing the inode numbers.
>
> You are spot on. Thank you, and sorry for my stupidity.

I don't think you're stupid.  It's hard to tell the difference between
two separate files with the same file size and a hardlink.  The
biggest clue is the number "2" in the second column.  If I recall
correctly, for directories, that's the number of entries in the
directory.  For files, that number is the number of hardlinks
referring to that file.

Even with that, it's hard to tell what files are hardlinked together,
and figuring it out by inode is a pain in the neck.  Personally, I
prefer symlinks, even if they introduce a small performance hit.
Readability counts, even in the filesystem.

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


Re: GUI for pickle read

2012-02-28 Thread Jerry Hill
On Tue, Feb 28, 2012 at 12:51 PM, Smiley 4321  wrote:
> Can I have some thoughts about - building a GUI to display the results of
> the pickle read?
>
> A prototype code should be fine on Linux.

It doesn't seem like it would be all that useful, though I may just be
lacking in imagination.  What would you do with such a thing?

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


Re: Python simulate browser activity

2012-03-15 Thread Jerry Hill
On Thu, Mar 15, 2012 at 10:54 PM, Chris Rebert  wrote:
> On Thu, Mar 15, 2012 at 7:23 PM, choi2k  wrote:
>> The application aims to simulate user activity including visit a
>> website and perform some interactive actions (click on the menu,
>> submit a form, redirect to another pages...etc)
>
> Did you look at Selenium?
> http://seleniumhq.org/

You might also be interested in Sikuli (http://sikuli.org/), which
uses Jython to write scripts to automate other programs using
screenshots.  It's pretty neat if you need to automate a GUI that is
otherwise difficult to deal with.

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


Re: Python Script Works Locally But Not Remotely with SSH

2012-04-02 Thread Jerry Hill
On Tue, Mar 27, 2012 at 8:51 PM, goldtech  wrote:
> I have a WinXP PC running an SSH server and I have a Linux PC with an
> SSH client  and logged into the XP seemingly OK. It's all on my
> personal LAN, the connection seems OK.
>
> I have a py file on the XP that I run via SSH from the Linux, it's:
>
> import webbrowser
> webbrowser.open('www.google.com')
>
> This runs OK started on the local XP PC, the browser Firefox opens and
> goes to the site, or it opens a tab to the site. But executing that
> same file via SSH does not open Firefox...doing it via SSH starts
> Firefox ( I see it begin in the process manager and I see web
> activity) but Firefox does not open it's window.
>
> Why the does the window not open when the script is started remotely?

How are you running the ssh server on the windows machine?  Is it a
windows service?  If so, what user does it run as, and is the service
configured to be allowed to interact with the desktop?

IIRC, by default most windows services run as a different user than
you, and do not have permission to interact with your desktop session.
 You may be able to get the firefox window to pop up on the ssh server
machine if you allow it to interact with the desktop, assuming that's
what you're trying to do.

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


Re: Python Script Works Locally But Not Remotely with SSH

2012-04-08 Thread Jerry Hill
On Sat, Apr 7, 2012 at 5:41 PM, Dennis Lee Bieber  wrote:
>        The WinXP machine would need to have X-client translator (something
> that redirects all the Windows native graphics into X protocol and ships
> it to the specified server machine).
>
>        As I recall -- such are not cheap applications.

X Servers for windows aren't expensive pieces of software anymore.
XMing is quite good, and free.  Cygwin also has an X server, but
Cygwin always seems like too much of a hassle to me.

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


Re: md5 check

2012-04-18 Thread Jerry Hill
On Wed, Apr 18, 2012 at 9:31 PM, contro opinion  wrote:
> i have download  file (gpg4win-2.1.0.exe  from
> http://www.gpg4win.org/download.html)
> when i run :
>
> Type "help", "copyright", "credits" or "license" for
>>>> import md5
>>>> f=open('c:\gpg4win-2.1.0.exe','r')
>>>> print md5.new(f.read()).hexdigest()
> 'd41d8cd98f00b204e9800998ecf8427e'
>
> it is not  =  f619313cb42241d6837d20d24a814b81a1fe7f6d gpg4win-2.1.0.exe
> please see   :gpg4win-2.1.0.exe  from  http://www.gpg4win.org/download.html
>
> why ?

Probably because you opened the file in text mode, instead of binary
mode.  Try opening the file this way:

 f=open('c:\gpg4win-2.1.0.exe','rb')

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


Re: syntax for code blocks

2012-05-01 Thread Jerry Hill
On Tue, May 1, 2012 at 1:07 PM, Kiuhnm
 wrote:
> If you had read the module's docstring you would know that the public
> version uses

Are you aware that you've never posted a link to your module, nor it's
docstrings?  Are you also aware that your module is essentially
unfindable on google?  Certainly nothing on the first two pages of
google results for 'python codeblocks' jumps out at me as a python
module of that name.

Perhaps you would have better luck if you either post the actual code
you want people to critique, or posted a link to that code.

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


Re: DateTime objectFormatting

2012-05-02 Thread Jerry Hill
On Wed, May 2, 2012 at 10:49 AM, Nikhil Verma  wrote:
> What i am able to achieve with this class object to return is :-
>
> Gen GI Monday  May 7
>
> I want that the this class should return object like this :-
>
> Gen GI Monday AM, May 7
> Pancreas Tuesday PM, May 8

Check the documentation for the strftime method:
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
 That has a list of the various formatting directives that can be used
to lay out your date and time as you wish.

In this case, instead of "%A %B %d", you probably want "%A %p, %B %d".
 That is, Full Weekday Name, followed by the AM/PM marker, then a
comma, then the Full Month Name and the day of month.

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


Re: English version for Mémento Python 3 (draft, readers needed)

2012-06-06 Thread Jerry Hill
On Wed, Jun 6, 2012 at 4:10 PM, Alec Ross  wrote:
> FWIW, English idiomatic usage includes "see overleaf", and "see over", for
> the obverse side of a page/sheet, i.e, the following page; and "see facing
> page", w/ the obvious meaning.

For what it's worth, I've never seen either of those constructs ("see
overleaf" and "see over").  Are they perhaps more common in a
particular academic context, or possibly more common in places that
use "British English" spellings rather than "American English"?
Typically I've just seen "see other side", or (very occasionally) "see
reverse" and "see obverse".

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


Re: using identifiers before they are defined

2012-06-12 Thread Jerry Hill
On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio  wrote:
> Suppose I have to define two functions, aa, and, bb that are designed to call
> each other:
>
>  def aa():
>     ...
>     ... a call of bb() somewhere in the body of aa
>     ...
>
>  def bb():
>     ...
>     ... a call of aa() somewhere in the body of bb
>     ...
>
>
> Whatever the order of definition of aa and bb the problem remains, one of the
> two identifiers is not known ...

This works just fine in python, exactly as you've written it.  What's
the actual problem you're having?

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


Re: Significant figures calculation

2011-06-24 Thread Jerry Hill
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano
 wrote:
> Really? It works for me.
>
>>>> import decimal
>>>> D = decimal.Decimal
>>>> decimal.getcontext().prec = 2
>>>>
>>>> D('32.01') + D('5.325') + D('12')
> Decimal('49')

I'm curious.  Is there a way to get the number of significant digits
for a particular Decimal instance?  I spent a few minutes browsing
through the docs, and didn't see anything obvious.  I was thinking
about setting the precision dynamically within a function, based on
the significance of the inputs.

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


Re: Python 3 syntax error question

2011-06-26 Thread Jerry Hill
On Sun, Jun 26, 2011 at 11:31 AM, Chris Angelico  wrote:
> Sure, but you don't _have_ to look at the diff. Just run it through
> 2to3 and see how it runs. Never know, it might work direct out of the
> box!

This has been my experience, by the way.  I've used a few small pure
python libraries written for python 2.x that don't have 3.x versions,
and they've all worked just fine with just a quick run through the
2to3 process.  I can't speak for larger libraries, or ones with lots
of compiled code, but my experience with 2to3 has been great.

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


Re: How do I access IDLE in Win7

2011-07-27 Thread Jerry Hill
On Wed, Jul 27, 2011 at 12:28 PM, W. eWatson  wrote:
> If I run cmd.exe and work my way down to  .../idlelib, I find nothing but
> idle.bat. strange. Hidden?  I can get into line mode by using python.exe.
> That is, I can type in print "abc", and get a result.

So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
(or where ever you installed python)?  If not, it sounds to me like
your python installation is screwed up.  I would re-install.

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


Re: How do I access IDLE in Win7

2011-07-27 Thread Jerry Hill
On Wed, Jul 27, 2011 at 3:34 PM, W. eWatson  wrote:
> On 7/27/2011 9:48 AM, Jerry Hill wrote:
>> So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\
>> (or where ever you installed python)?  If not, it sounds to me like
>> your python installation is screwed up.  I would re-install.
>
> Yes, I have both. Neither shows anything on the monitor when I double click
> them.

Oh, I guess I misunderstood.  Go ahead and open that cmd.exe window
back up.  Please run the following and report back the results.  In
the cmd.exe window run:

assoc .py
assoc .pyw
ftype Python.File
ftype Python.NoConFile

Those four commands should show us how the python file associations
are set up on your computer.

Then, let's try to run idle and capture whatever error message is
popping up.  I don't think you've mentioned what version of python you
have installed.  The following is for 2.6, since that's what I have
installed here, but it should work on any other version if you swap in
your installation directory for the 2.6 one below.  Still in your
cmd.exe window, run the following:

c:\Python26\python.exe C:\Python26\Lib\idlelib\idle.py

If you get an exception, please copy and paste the details for us.  If
that works and opens idle, please try running this:

C:\Python26\Lib\idlelib\idle.py

Based on the behavior you've described so far, that ought to fail, and
hopefully give some sort of message or exception for us to diagnose.

PS: If you're just trying to get things working, and don't care what
might be wrong, I would recommend just re-installing python.  That
ought to clean up all the file associations and set things up properly
for you.  That's likely the quickest way to just get things working.

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


Re: How do I access IDLE in Win7

2011-07-28 Thread Jerry Hill
On Wed, Jul 27, 2011 at 5:26 PM, W. eWatson  wrote:
> .py=Python.File
> .pyw=Python.NoConFile
> Python.File="C:\Python25\python.exe" "%1" %*
> Python.File="C:\Python25\python.exe" "%1" %*
> Python.NoConFile="C:\Python25\pythonw.exe" "%1" %*

That all looks good.

> I cannot copy from the cmd window. It ends with [errorno 13] Permission
> denied to c:||Users\\Wayne\\idlerc\\recent-files.lst'

That sounds like the root of the problem, then.  I'm assuming Wayne is
your username, but I don't know why you wouldn't have permission to
access something in your own user directory.  Can you try deleting
that file in the windows explorer?  You could try messing with the
permissions, but I doubt you care about a recent file list that sounds
several months old.  You might even try removing (or renaming) the
whole C:\Users\Wayne\idlerc folder.  Idle should re-build anything it
needs if it's not there when you start up.

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


Re: Only Bytecode, No .py Files

2011-07-29 Thread Jerry Hill
On Fri, Jul 29, 2011 at 8:51 AM, John Roth  wrote:
> Sorry. I thought what you posted was from the OP. I guess I don't
> really expect someone to post a completely irrelevant trace in a
> thread started by someone who has a problem.

I'm not sure why you would think that that post was by the original
poster, or that it was irrelevant.  It seems to me that it
demonstrated exactly the behavior Eldon was complaining about as a
normal part of the operation of lots of normal unix programs.  Thomas
even said that in the very first line of his post (after the quoted
bit).

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


Re: What is xrange?

2011-07-29 Thread Jerry Hill
On Fri, Jul 29, 2011 at 3:36 PM, Billy Mays  wrote:
> Is xrange not a generator?  I know it doesn't return a tuple or list, so
> what exactly is it?  Y doesn't ever complete, but x does.
>
> x = (i for i in range(10))
> y = xrange(10)

xrange() does not return a generator.  It returns an iterable xrange
object.  If you want the iterator derived from the iterable xrange
object, you can get it like this:  iterator = y.__iter__()

See http://docs.python.org/library/functions.html#xrange for the
definition of the xrange object.

http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/
seems to cover the differences between iterables, iterators, and
generators pretty well.

Some more reading:
http://docs.python.org/howto/functional.html
http://www.python.org/dev/peps/pep-0255/
http://www.python.org/dev/peps/pep-0289/

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


Re: Determine what msvcrt.getch() is getting?

2011-08-16 Thread Jerry Hill
On Tue, Aug 16, 2011 at 5:43 PM, John Doe  wrote:
> Whatever msvcrt.getch() is returning here in Windows, it's not within
> the 1-255 number range. How can I determine what it is returning?
>
> I would like to see whatever it is getting.

Just print it.  Like this:

import msvcrt
ch = msvcrt.getch()
print (ch)

for a bit more information, do this instead:
import msvcrt
ch = msvcrt.getch()
print(type(ch), repr(ch), ord(ch))

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


Re: Wait for a keypress before continuing?

2011-08-16 Thread Jerry Hill
On Tue, Aug 16, 2011 at 5:59 PM, John Doe  wrote:
> No. I am running this from within Windows, all sorts of Windows.

What does that mean?  You seem very resistant to answering anyone's
questions about your code.  Is your code run from the command line, or
does it have a GUI?  If it has a GUI, what windowing toolkit are you
using?  If you have code that's not working, please, show us a short,
run-able bit of sample code that demonstrates the problem you're
experiencing. Describe the behavior you see, the behavior you expected
instead, and the full text of any traceback you may be getting.

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


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Jerry Hill
On Thu, Aug 18, 2011 at 11:19 AM, noydb  wrote:
> I am being passed the list of strings.  I have variables set up
> already pointing to files.  I need to loop through each variable in
> the list and do things to the files.  The list of strings will change
> each time, include up to 22 of the same strings each time.

If you have a mapping of strings to values, you should just go ahead
and store them in a dictionary.  Then the lookup becomes simple:

def foo(list_of_strings):
mapping = {
"bar0": "/var/log/bar0.log",
"bar1": "/usr/local/bar/bar1.txt",
"bar2": "/home/joe/logs/bar2.log",
}
for item in list_of_strings:
filename = mapping[item]
do_something(filename)


(Untested)

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


Re: Reading pen drive data

2011-09-03 Thread Jerry Hill
On Sat, Sep 3, 2011 at 12:21 PM, mukesh tiwari  wrote:

> I am getting
> Traceback (most recent call last):
>  File "Mount.py", line 7, in 
>observer = QUDevMonitorObserver(monitor)
> NameError: name 'QUDevMonitorObserver' is not defined
>
> Could any one please tell me how to avoid this error .
>

It looks to me like that should be pyudev.QUDevMonitorObserver, shouldn't
it?

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


Re: embedding interactive python interpreter

2011-03-27 Thread Jerry Hill
On Sun, Mar 27, 2011 at 9:33 AM, Eric Frederich
 wrote:
> This is behavior contradicts the documentation which says the value
> passed to sys.exit will be returned from Py_Main.
> Py_Main doesn't return anything, it just exits.
> This is a bug.

Are you sure that calling the builtin exit() function is the same as
calling sys.exit()?

You keep talking about the documentation for sys.exit(), but that's
not the function you're calling.  I played around in the interactive
interpreter a bit, and the two functions do seem to behave a bit
differently from each other.  I can't seem to find any detailed
documentation for the builtin exit() function though, so I'm not sure
exactly what the differences are.

A little more digging reveals that the builtin exit() function is
getting set up by site.py, and it does more than sys.exit() does.
Particularly, in 3.1 it tries to close stdin then raises SystemExit().
 Does that maybe explain the behavior you're seeing?  I didn't go
digging in 2.7, which appears to be what you're using, but I think you
need to explore the differences between sys.exit() and the builtin
exit() functions.

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


  1   2   3   4   5   >