Extending the 'function' built-in class

2013-12-01 Thread G.
Hi, I can't figure out how I can extend the 'function' built-in class. I tried:
  class test(function):
def test(self):
  print("test")
but I get an error. Is it possible ?

Regards, G.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extending the 'function' built-in class

2013-12-01 Thread G.
Le 01-12-2013, Roy Smith  a écrit :
>
> class foo(type(open)):
> pass
>
> I get:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: Error when calling the metaclass bases
> type 'builtin_function_or_method' is not an acceptable base type
>
> So, we're back to asking what version you're using and what error 
> message you got.

Hi, I don't care that much for the version, since I wanted rather to perform
some tests. I tried your code with various versions and got the same message
than yours. Thus I guess the type can't be extended. Regards, G.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extending the 'function' built-in class

2013-12-01 Thread G.
Le 01-12-2013, Gary Herron  a écrit :
> And in particular: What 'function' built-in class?  I know of no such 
> thing, and the error message I get with your code says exactly that:
>NameError: name 'function' is not defined
> Did you not get that same error?

Yes, indeed. The 'function' built-in class was the following one:
>>> type(lambda x: 2*x)


but I am interested by answers concerning other similar types also.

Regards, G.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extending the 'function' built-in class

2013-12-02 Thread G.
Le 02-12-2013, Steven D'Aprano  a écrit :
> There are plenty of ways to extend functions. Subclassing isn't one of 
> them.

Thank you very mych for your complete answer; I falled back to your last
proposal by myself in my attempts; I am happyt to learn about the other ways
also.

Regards, G.
-- 
https://mail.python.org/mailman/listinfo/python-list


Could you please give me some advise on this piece of code?

2011-09-12 Thread G.
Dear all,
I am a python newbie, but I intend to program a python script that
communicates with Labview via a UDP socket.
I managed to send LabView strings, but the other way around is not
working.
The code seems to stop working while in the first while loop. I can
see the word "test" being print out.

When I start LabView UDP_sender.vi it is supposed to send a string
back to python, but sometimes it ends with an error saying the port
and the ip is already in usage. Do I have to start first LabView or
the python scrip when listening to LabView, please?

It would be great if you could have a look on my code and could maybe
see why it does nothing after "print test", please.

Thank you very much.

Kind regards,
G.



# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="User"
__date__ ="$11.09.2011 19:34:03$"

if __name__ == "__main__":
print "Das ist ein Test"

import socket
import time

#Define global variables for UDP_IP and UDP_Port, needs to be changed
for PETRA-3
#global UDP_IP
UDP_IP="127.0.0.1"
print "UDP_IP is", UDP_IP

#global UDP_PORT
UDP_PORT=21312
print "UDP_PORT is", UDP_PORT





def openUDPSocket(UDP_IP,UDP_PORT):
#UDP_IP="127.0.0.1"
#UDP_PORT=5005
print "Creating socket ..."
sock=socket.socket( socket.AF_INET, # Internet
socket.SOCK_DGRAM ) # UDP
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#sock.setblocking(0)
#sock.bind((UDP_IP,UDP_PORT))
#sock.listen(1)
print "Done."
return sock

def fastPump(sock):
# Start pumping and return
MESSAGE="pumpfast"

   # print "UDP target IP:", UDP_IP
   # print "UDP target port:", UDP_PORT
   # print "message:", MESSAGE

sock.sendto( MESSAGE, (UDP_IP, UDP_PORT) )

def slowPump(sock):
MESSAGE="pumpslow"
sock.sendto( MESSAGE, (UDP_IP, UDP_PORT) )


pumpsocketUDP=openUDPSocket(UDP_IP,UDP_PORT)


# Receive messages
counter_while_loop=0
print "test"
while counter_while_loop < 3:
data,addr = pumpsocketUDP.recvfrom(1024)
print "test"
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", data,"'"
counter_while_loop=counter_while_loop+1


counter_while_loop=0

while counter_while_loop < 3:
fastPump(pumpsocketUDP)
time.sleep(5)
slowPump(pumpsocketUDP)
time.sleep(3)

counter_while_loop=counter_while_loop+1
print "Counter_while_loop", counter_while_loop


# Close socket
pumpsocketUDP.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


i need your help

2005-12-18 Thread g
  hi.i dont know it is true or not to write you about that.I ve problem to run phyton in my personal computer.I install it and there is no error when installing but when i want to run pythonw.exe, no window opened.Only i can run python.exe in dos shell when i click.when cilicking to w9xpopen.exe gives an message saying can not run...I am using winxp as an operating system.I wonder how can i over come that stuation as a new python learners.If you help me to overcome to such problem i will be so happy...   Thanx for reading that e-mail, and sorry for taking your time..    Emrah GÜN     Middle East Technical University, Computer education and instruction technology department  1st year student.
 __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Re: HTML parsing bug?

2006-01-30 Thread G.
> //   - this is a comment in JavaScript, which is itself inside
> an HTML comment

This is supposed to be one line. Got wrapped during posting.

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


Subclassing int

2007-07-23 Thread G

Hi,

   I am trying to subclass int to allow a constructor to accept None. I am
trying the following

class INT(int):
   def __init__(self, x):
   if x is  None:
   return None
   else:
   int.__init__(x)

b = INT(x=None)

When i run the previous code i get the following error:
b = INT(x=None)
TypeError: int() argument must be a string or a number, not 'NoneType'.

Do you guys know why the if statement is not evaluated?

Thanks for your help
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Subclassing int

2007-07-23 Thread G

Thanks a lot Matt and Steve. I replaced __int__ with __new__ and it worked


On 7/23/07, Matt McCredie <[EMAIL PROTECTED]> wrote:


Do you guys know why the if statement is not evaluated?


For immutable types __new__ is called before __init__. There are some
details here: http://docs.python.org/ref/customization.html. Also, it
isn't really clear what you want to do if the value is set to None anyway.
In your example you return None, but that simply won't work since you can't
return anything from __init__. Perhaps your need could be met by a function
instead:


def INT(x):
if x is None:
return None
else: return int(x)


-Matt



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

With Statement Contexts and Context Managers

2007-07-31 Thread G
Hi,

   Could somebody please point me to a good resource to read about  the
contexts, context managers, and with_statement

Best Rgd,
   G.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: With Statement Contexts and Context Managers

2007-07-31 Thread G
Great thanks.

On 7/31/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> On Tue, 2007-07-31 at 14:57 -0400, G wrote:
> > Hi,
> >
> >Could somebody please point me to a good resource to read about
> > the contexts, context managers, and with_statement
> >
>
> There's PEP 343 at http://www.python.org/dev/peps/pep-0343/. I don't
> know if that fits your definition of "good," but it should at least get
> you started.
>
> HTH,
>
> --
> Carsten Haese
> http://informixdb.sourceforge.net
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

wxpython with python 2.5

2007-08-02 Thread G
Hello,


 I am trying to get wxpython to run with python 2.5 without any success.
wx works prefectly in python 2.4. below is the error code i get when i try
to run the code.
File "demo.py", line 3, in 
import Main
  File "/tmp/wxPython/Main.py", line 32, in 
import wx  # This module uses the new wx namespace
ImportError: No module named wx

Any help in getting wxpython to run in 2.5 would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list

os.system with cgi

2008-03-03 Thread G
Hi,

   I have the following peace of code

def getBook(textid, path):
url = geturl(textid)
if os.path.isfile(path + textid):
f = open(path + textid)
else:
os.system('wget -c ' + url + ' -O ' path + textid)
f = open(path + textid)
return f

The reason I am not using urllib is that I want to have random access within
the downloaded file.

When i execute the file from a regular python script I get the file
downloaded and a handle for the file returned.
When I execute the file from a python cgi script i get an error saying that
the file doesn't exist. In other words the call to os.system is not running.
Could someone please point out what the problem with that peace of code
running as a cgi script.

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

Re: question about string formatting

2008-04-09 Thread G
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'en_US.UTF-8'
>>> locale.format('%.2f', 1021212.12, True)
'1,021,212.12'
>>>

On Wed, Apr 9, 2008 at 1:04 PM, Kelie <[EMAIL PROTECTED]> wrote:

> Hello,
>
> Is there something in Python built-in function or library that will
> convert a number 1205466.654 to $1,205,466.65? To add the "$" sign and set
> the decimal place is not a problem, but I don't know how to add the
> thousands delimiter.
>
> Thanks,
>
> --
> Kelie
> UliPad  is my Python editor.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can't run any script without it failing due to calling tkinter for no reason

2012-10-14 Thread Adam G
On Sunday, October 14, 2012 7:19:24 PM UTC-7, Benjamin Kaplan wrote:
> On Sun, Oct 14, 2012 at 6:47 PM,   wrote:
> 
> > Hello All,
> 
> >
> 
> >
> 
> > I'm running python 3.2 on Freebsd 9.0 Release and I must've screwed up my 
> > environment somehow, because now I can't run any script without it failing 
> > and throwing:
> 
> > ** IDLE can't import Tkinter.  Your Python may not be configured for Tk. **
> 
> >
> 
> > Yet none of my scripts use tkinter nor call that module. They're simple 
> > network scraping scripts. I use pydev and eclipse and must've fat fingered 
> > something that screwed up my python environment, but I haven't the 
> > slightest clue on how to fix it. I can run my scripts in idle no problem, 
> > but I've built them as command line apps. I've tried uninstalling python 3 
> > and reinstalling it to no avail. What did I do, and how can I fix it?
> 
> >
> 
> > Thanks,
> 
> > Adam
> 
> > --
> 
> 
> 
> IDLE uses Tkinter. If you don't have Tk installed, just run the
> 
> scripts from the terminal or pick a different IDE.



Hi Ben,


Your reply instantly triggered my aha moment and I figured it out. I had an 
import to idlelib in one of my modules dependencies from an eclipse 
auto-import. I feel foolish for not seeing it sooner. I use eclipse and pydev 
and use a module to do all the heavy network code for my front end command line 
scripts. In that module I used a function variable called host where eclipse, 
oh so helpfully, gave me the option of resolving an import I never asked for by 
automatically importing some module from idlelib. It was from idlelib import 
host as HOST or something to that effect. Damn eclipse does that to me from 
time to time and it happens so fast I don't even see what it does. Thanks for 
the reply and helping me see my erroneous ways.

Cheers,
Adam
-- 
http://mail.python.org/mailman/listinfo/python-list


SMS

2011-07-20 Thread TERESA G
One method you can use is to connect to an SMS API provider from your
web application, which will enable you to send SMS via an internet
connection, typically using a protocol like HTTP; You can try Nexmo
SMS API,  it supports HTTP REST and SMPP and we have documentation
published in our website with information and examples on how to
connect and send, which for a programmer in any language can be pretty
simple.

http://nexmo.com/documentation/libs/index.html

Examples for Python are still to come to the documentation page,
however, you can try github and find code to send sms for python in
github. e.g. https://github.com/marcuz/pynexmo

With Nexmo, you can send to 200 countries, and it has Long Numbers
available in a few countries for inbound traffic.You need to have a
CallBack URL for inbound to which Nexmo sends a request for each
incoming message to your long number.

It is a pay as you go service, so you decide how much you need to buy
to send SMS (pricing per country/operator is on the website). For
inbound, you pay per long number monthly (not per message). The end
user does not pay for receiving.

http://nexmo.com

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Run Windows commands from Python console

2017-09-03 Thread g . morkvenas
Hello,

I run Python console in Windows. Can I run cmd prompt commands there?

If I run command dir I have:

>>> dir

 
What does it means?

If i trying to create file I have error:

>>> type NUL > hh.txt
  File "", line 1
type NUL > hh.txt
   ^
SyntaxError: invalid syntax


What means line below:

File "", line 1

I don't have any  file.


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


acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
My program has two circles: one stationary circle, drawn at a random location; 
and one moving circle, consistently drawn in the same place in the graphics 
window.

The moving circle moves towards the stationary one.  However, when the moving 
circle hits the stationary one (when the x-coordinates of the circles' centers 
are equal), I want the moving circle to stop moving and then disappear.

I tried the command acircle.getCenter() to determine when the centers are 
equal, but it doesn't work; I suspect because the centers are never truly 
equal, and only come within something like .01 pixels of each other.  So to 
account for the approximation, I used the math function "isclose":

move_moving_circle = True

while move_moving_circle:
moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
time.sleep(0.01)

if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), 
rel_tol=1e-4, abs_tol=0.0):
move_moving_circle= False

else:
move_moving_circle = True


But this doesn't work.  Apparently isclose can't be applied to points - only 
floating-point decimals.


So now, I want to convert the output of "acircle.getCenter()" to Cartesian 
(x,y) coordinates for both circles.  Then I can use the two circle centers' 
x-coordinates in the if statement.

Currently, acircle.getCenter() outputs this:




I don't understand/can't use the format that the locations are printed in.

How do I convert the above format to "usable" Cartesian coordinates?  Or is 
there a simpler way to solve this problem?

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


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
I did try that.  The problem is that I already declared a point 
moving_object_center = (-555,-555), because that's the point I used as the 
center to draw the moving_object circle itself.  So the 
moving_object_center.getX() will return -555 no matter what I do.

That's why I need to calculate the center using some attribute of the circle, 
not the center point - because the circle moves, but the point that I declared 
as the initial center point will never change.

I'm not totally sure what you mean by "graphics library", but these are all the 
import statements I'm using at the beginning.

from graphics import *
import datetime
import random
from math import *
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
> But your code has:
> 
>  moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
> 
> so won't that move the circle and change what:
> 
>  moving_circle.getCenter()
> 
> returns?

Yes, moving the circle changes the value of moving_circle.getCenter(). The 
problem is interpreting the output. The command gives , and I don't know how to determine the x-coordinate of the 
center from that output. This is my problem. I can't translate the .getCenter() 
output to Cartesian coordinates.



> The initial point won't change, but that's just where the circle was 
> originally.

> Are you sure that it doesn't change? Have you printed out 
> moving_circle.getCenter().getX() and moving_circle.getCenter().getY() 
> and seen that they aren't changing?

Distinguish between the circle's center and the initial center point I 
declared. My program can output the former, but it's in a format that I don't 
understand: .

As for the initial center point (I'll call it moving_circle_*initial*_center 
instead), it won't change at all throughout the program execution.

I need to know the x- and y-coordinates of moving_circle.getCenter() at any 
point in time. I can't use the center of the circle *before* it started moving, 
because that value is static (in other words, 
moving_circle_initial_center.getX() and moving_circle_initial_center.getY() 
never change).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-24 Thread G Yu
Ah, I get it now.  I have to store the acircle.getCenter() in a point Point, 
and then access Point.getX() and Point.getY() separately.  It was just that 
middle step that I was missing.  Thanks so much!
-- 
https://mail.python.org/mailman/listinfo/python-list


recent-files

2023-03-28 Thread g...@uol.com.br
   In Python 3.11.2,  the recent-files list keeps always increasing because
   it is impossible to edit the list; the corresponding .txt file has
   disappeared.
   Please help!

   Giorgio Gambirasio
   g...@uol.com.br

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


How best to handle SystemError in ctypes callback

2022-01-05 Thread Jarrod G
With the following code:

import ctypes
> import readline
> from ctypes.util import find_library
>
> rl = ctypes.cdll.LoadLibrary(find_library('readline'))
>
> rl_redisplay = rl.rl_redisplay
> rl_redisplay.restype = None
> rl_redisplay.argtypes = None
>
> rl_redisplay_function = ctypes.c_void_p.in_dll(rl, 'rl_redisplay_function')
>
> def _wrapper():
> rl_redisplay()
>
> fp = ctypes.CFUNCTYPE(None)(_wrapper)
> rl_redisplay_function.value = ctypes.cast(fp, ctypes.c_void_p).value
>
> input('enter ctrl-c now')
>

What is the best or correct way to handle SystemError when a Ctrl-c happens
at the input prompt? Is a try/except around rl_redisplay the best or
correct approach?

Based on the docs for SystemError (
https://docs.python.org/3/library/exceptions.html#SystemError), I don't
want to mask/hide an internal error.

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


correct way to catch exception with Python 'with' statement

2016-11-28 Thread g thakuri
Dear Python friends,

Any suggestion on how to add exception and make the below program look
better  ,  I am using Python 2.7 and Linux



def create_files_append():
"""  """
try:
os.makedirs(QA_TEST_DIR)
except:
raise OSError("Can't create directory (%s)!" % (QA_TEST_DIR))

# Create few files and write something
for i in range(1000):
with open(os.path.join(QA_TEST_DIR,"filename%d" %i),'w') as f:
 f.write("hello")

# Append the files
for i in range(1000):
with open(os.path.join(QA_TEST_DIR,"filename%d" %i),'w') as f:
 f.write("hello")

return True

---

What will be the best  way to catch the exception in the above program  ?
Can we replace both the  with statement in the above program with something
like below

try:
for i in range(1000):
   with open(os.path.join(QA_TEST_DIR,"filename%d" %i),'w') as f:
   f.write("hello")
except IOError as e:
raise

Regards,
PT
-- 
https://mail.python.org/mailman/listinfo/python-list


Simple code and suggestion

2016-11-30 Thread g thakuri
Dear Python friends,

I have a simple question , need your suggestion the same

I would want to avoid using multiple split in the below code , what options
do we have before tokenising the line?, may be validate the first line any
other ideas

 cmd = 'utility   %s' % (file)
 out, err, exitcode = command_runner(cmd)
 data = stdout.strip().split('\n')[0].split()[5][:-2]

Love,
PT
-- 
https://mail.python.org/mailman/listinfo/python-list


Tracing memory in production django process with systemtap

2016-08-04 Thread Lei G
Hi all,

  Recently I met some python memory problems with Django and uwsgi, and found 
to find exactly which part is causing the problem, so I went to use systemtap 
to tracing the problem, and here are some problems that I met:

  It seems python needs to patch some 'probes' into the source code, but the 
patch for python version like 2.x ~ 3.x is not in the main python branch,

  If someone has used it, I want to know whether they are safe in the 
production? 

  patch list: https://www.jcea.es/artic/python_dtrace.htm
  bug list: http://bugs.python.org/issue13405
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tracing memory in production django process with systemtap

2016-08-04 Thread Lei G
在 2016年8月5日星期五 UTC+8上午1:41:04,Lei G写道:
> Hi all,
> 
>   Recently I met some python memory problems with Django and uwsgi, and found 
> to find exactly which part is causing the problem, so I went to use systemtap 
> to tracing the problem, and here are some problems that I met:
> 
>   It seems python needs to patch some 'probes' into the source code, but the 
> patch for python version like 2.x ~ 3.x is not in the main python branch,
> 
>   If someone has used it, I want to know whether they are safe in the 
> production? 
> 
>   patch list: https://www.jcea.es/artic/python_dtrace.htm
>   bug list: http://bugs.python.org/issue13405

Or some advice to do this debugging on ubuntu + systemtap + python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Trying to compile Python 3.5 on Linux Mint 19, getting compiler warnings and failing tests

2019-02-18 Thread Marcin G
My boss wants my code to run on Python 3.5, so I thought I'd install 3.5 to be 
able to ascertain this.

But Linux Mint 19 ships with Python 3.6 and python.org only provides source 
code for 3.5.6. So I 
thought I'd try compiling 3.5.6 myself.

This produced compiler warnings about: comparison between signed and unsigned, 
switches falling though, use of deprecated macros in glibc headers and too big 
object sizes leading to overflows in memcpy. This worries me the most, because 
it looks like undefined behavior to my untrained eye. I wonder if my system is 
misconfigured? Or if the configure script picks wrong sizes for some reason? Is 
there incompatibility between Python 3.5 and newer glibc headers?

In addition, make test shows up one failing test: test_ssl.

All I want is to have an installation that is not broken. If the above failures 
are false positives, I can gladly ignore them; however, since (unsupressed) 
warnings and failing tests are usually a sign of serious problems, I wonder 
what should I do get a functional installation?

I do believe I should have all dependencies installed. First, I kept installing 
libraries until `make` stopped showing me info about missing bits for optional 
modules. Then, just to make sure, I did sudo apt-get build-dep python3. Problem 
is still not solved, however.

Pastes:

Full log. Just 
warnings. Just 
failing tests.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Trying to compile Python 3.5 on Linux Mint 19, getting compiler warnings and failing tests

2019-02-18 Thread Marcin G
Hmm. From looking at your full log (THANK YOU for posting that, btw -
so many people don't), it looks like an issue with certificate
checking. Might be a bug in the test itself. Does the same thing
happen with a more recent Python build? It could be a weirdness with
specific versions of OpenSSL.

Hmm, my Googling brought me this:

https://bugs.python.org/issue30714

Apparently, the test fails with newer versions of openssl and the test was 
fixed in 3.7, 3.6 and 2.7, but for some reason 3.5 was removed from the 
versions field of this bug report.
-- 
https://mail.python.org/mailman/listinfo/python-list


'python' is not recognized as an internal or external command

2019-09-01 Thread G Kishore
Hi Team,

I was installing python in my new windows 10 machine and cpuld able to access 
python from command window when the location is where I have installed python.

The same I have tried to enter the command from Desktop location but "'python' 
is not recognized as an internal or external command,"  error is thrown. Done 
the path variable in the environmental variables as the location where python 
is installed.

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


Errors in python\3.8.3\Lib\nntplib.py

2020-04-29 Thread G Connor
module: python\3.8.2\Lib\nntplib.py
lines 903-907
---
for line in f:
if not line.endswith(_CRLF):
line = line.rstrip(b"\r\n") + _CRLF
if line.startswith(b'.'):
line = b'.' + line
---

When I try to submit a Usenet post, I get this:


Traceback (most recent call last):
  File "D:\python\3xcode\Usenet\posting\NNTP_post.py", line 12, in 
news.post(f)
  File "D:\python\3.8.2\lib\nntplib.py", line 918, in post
return self._post('POST', data)
  File "D:\python\3.8.2\lib\nntplib.py", line 904, in _post
if not line.endswith(_CRLF):
TypeError: endswith first arg must be str or a tuple of str, not bytes


Also, line 906:
if line.startswith(b'.'):
 looks like it should be:
if not line.startswith(b'.'):
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Errors in python\3.8.3\Lib\nntplib.py

2020-04-29 Thread G Connor
On 4/29/2020 5:29 PM, Chris Angelico wrote:


> Try opening the file in binary mode instead.


Changed:  f = open(postfile,'r')to :  f = open(postfile,'rb')
and it worked.

Thanks man!





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


Re: Windows vs Linux [was: p2exe using wine/cxoffice]

2005-10-26 Thread Tim G
Thomas Heller wrote:
> FYI, if you don't know this already: You also can resize the console without
> going through the properties menu with 'mode con cols=... lines=...'.

Good grief! I haven't used "mode con" in years; forgotten
it even existed! Thanks for bringing that back, Thomas.

TJG

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


Re: Windows vs Linux

2005-10-26 Thread Tim G

Bernhard Herzog wrote:
> "Tim Golden" <[EMAIL PROTECTED]> writes:
>
> > But as far as I can tell
> > from my experience and from the docs -- and I'm not near a
> > Linux box at the mo -- having used ctrl-r to recall line x
> > in the history, you can't just down-arrow to recall x+1, x+2 etc.
> > Or can you?
>
> You can.  It works fine on this box, at least.
> GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu)
> libreadline 4.2a

Sadly, this seems not to be the case on my Ubuntu Breezy:
bash 3.00.16, libreadline 4.3/5.0 (not sure which one
bash is using). ctrl-r is fine; but you can't down-arrow
from there; it just beeps at you. Is there some setting I'm
missing?

TJG

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


Re: Problems with threaded Hotkey application

2005-11-23 Thread Tim G
And just to confirm, it does in fact work. If you move the
RegisterHotKey line to within the thread's run method, the thread's
message loop picks up the hotkey press.

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


Re: Problems with threaded Hotkey application

2005-11-23 Thread Tim G
One obvious point is that, according to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefWM_HOTKEY.asp

the WM_HOTKEY message is posted to the queue *of the thread which
registered the hotkey*. I haven't yet tried it myself to see, but in
your example the main thread registers the hotkey, and the KeyCatch
thread is waiting to receive it.

TJG

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


Call for a cooperation

2005-12-06 Thread G. Sica
Dear all,
I'm a PhD researcher in logic at the University of Leiden in Holland.
At the present I'm doing a work about the implementation of some parts
of the Braille code related to the representation of the logical and
mathematical symbols.
In order to the well development of this work I will need a little
software helping me in the execution of some automatic operations
related to the analysis of Braille code.
I've written the structure of the software I need. 
You can find it (including the related information) at the web-page:
http://www.polimetrica.org/indexen.html 
I'm writing to this list because would like to know if there is someone
interested in writing the software by using Python. 
It should then be distributed under terms of the GNU GPL license.
I'm sorry, but my skills related to programming languages are very poor.
Many thanks in advance for the help.

All the best,
nico

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


Re: Problem remotely shutting down a windows computer with python

2005-01-04 Thread Tim G
> I have a problem when using the python script found here:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
>
> It is a script to remotely shutdown a windows computer.  When I use
it,
> the computer shuts down, but doesn't power off like with a regular
> shutdown. It stays on the "Safe to power off" screen and I have to
push
> the power button to actually power off.  Anyone know why this happens
> with this script?  Thanks for any help.
>
> Eric

I see that others have answered the question
pretty completely, but just to add the obligatory
WMI solution:
[ assumes you're using the wmi module from
http://tgolden.sc.sabren.com/python/wmi.html ]



import wmi
c = wmi.WMI (computer="other_machine", privileges=["RemoteShutdown"])
os = c.Win32_OperatingSystem (Primary=1)[0]
os.Win32Shutdown (Flags=12)


The Flags=12 bit should shut down all the way.

TJG

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


Re: Installing IPython on win2k

2005-01-08 Thread Tim G
Dave Merrill wrote:
> Hi, I'm new to python, and ipython, but not to programming, having
trouble
> getting ipython installed on windows 2000, python 233. Any help would
be
> much appreciated; I'm sure I'm being some basic flavor of dense...

First of all, rest assured that it does work (and quite
easily) so welcome to Python and iPython and I hope
the going's a bit smoother as you go along.

> Then downloaded ipython-0.6.6.zip and unzipped it. When I
double-click
> setup.py, I get only a brief wait cursor; nothing else happens, and
> importing ipython as a test fails.

First of all, ipython isn't really an import into python; you run
it and it runs python (if you understand me). So when you've
installed it, I think it puts an item on your start menu. On
linux, it puts an executable ipython onto your path.

I've just downloaded and run the setup.py, and it does
create a Start Menu item which will start iPython. Look
out for that and see if it does the business.

> Both files in the scripts dir, ipython and pycolor, have no filename
> extension, which seems odd to my newbie eye. I tried renaming them to
.py,
> still no difference.

This is a unixism. Some unix types decry the use of file extensions
because the information the extension gives -- which executable
program to use -- is already embedded in the first line of a file.

>
> My apologies for this basic question, and my no doubt ignorant
flailing
> about. Very much looking forward to getting this working.
> 
> Thanks,
> 
> Dave Merrill

Good luck and happy hunting

TJG

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


Re: COM problem .py versus .exe

2005-06-29 Thread Tim G
Greg Miller wrote:
> I tried the code snippet using win32api.GetFileVersionInfo(), what I
> get now is the following when running on the executable machine:
>
> . . . FileFlagsMask => 63
> FileType => 2
> FileVersionMS => 65536
> FileVersionLS => 1
> Signature => -17890115
> FileSubtype => 0
> FileFlags => 0
> ProductVersionLS => 1
> FileDate => None
> ProductVersionMS => 65536
> FileOS => 4
> StrucVersion => 65536

> I can't find too much on the 'net about these output values.

>From the pywin32 help entry for GetFileVersionInfo:

"Information to return: \\ for VS_FIXEDFILEINFO"

Google for VS_FIXEDFILEINFO and hit "I'm Feeling Lucky". You've
still got to work out how to piece the values together, but I'm
sure you're just as capable of doing that as I am. (And probably
more so).

TJG

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


Re: [Tutor] How to get 4 numbers from the user in one line for easycomparision?

2005-07-03 Thread Alan G

> I  Just need to figure out how to get 4 numbers from 
> the player on one line for easy comparison, 

Unless there is a set of batteries somewhere that I don't know 
about I think you have to rely on reading the line as a string 
and then splitting it.

line = raw_input('Type 4 numbers separated by spaces: ')
numbers = [int(n) for n in line.split(' ')]

HTH,

Alan G.

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


c/c++ extensions and help()

2005-07-28 Thread Lenny G.
Is there a way to make a c/c++ extension have a useful method
signature?  Right now, help(myCFunc) shows up like:

myCFunc(...)
  description of myCFunc

I'd like to be able to see:

myCFunc(myArg1, myArg2)
  description of myCFunc


Is this currently possible?

Thanks,
Lenny G.

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


constructing bytestrings

2005-08-11 Thread Lenny G.
I use 's = os.read(fd, 12)' to grab 12 bytes from a file.  Now, I want
to create a string, s1, which contains 16-12=4 bytes: 4,0,0,0, followed
by the contents of s.

I know how to 's1 = "\x04\x00\x00\x00"' and how to 's3 = s1+s', but I
don't know how to construct s1 dynamically (i.e., given N, construct
"N" followed by N-1 "0", where "N" and "0" are single byte values with
N<16).  How do I do this?

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


fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Suppose I have a python module named Hippo.  In the Hippo module is a
class named Crypto.  The Crypto class wants to 'from Crypto.Hash import
SHA' which refers to the module/classes in python-crypto.  Other
classes in the Hippo module want to 'import Crypto' referring to
Hippo.Crypto.

How do I do this?  For now, I just renamed my Hippo.Crypto to
Hippo.HippoCrypto and everything is okay as long as I use 'HippoCrypto'
to refer to that class.  But, this is of course redundant.  What I
really want to do is use

'import Crypto' # to refer to python-crypto
'import Hippo.Crypto'   # to refer to Hippo.Crypto

but the 2nd item doesn't seem to work from within the Hippo module.
What am I missing?

  Thanks,
  Lenny G.

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


Re: fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Thanks George.  But I have to apologize -- I think I used the wrong
term in my question.  Hippo is actually a package, not a module.  So I
have:

Hippo/
  __init__.py
  Crypto.py
  Potamus.py

And inside Crypto.py, I need to access python-crypto's Crypto.Hash
package.  Inside Potamus.py, I need to access Hippo.Crypto, e.g.,

Hippo/
  __init__.py
  Crypto.py# wants to import python-crypto's Crypto.Hash
  Potamus.py   # wants to import Hippo's Crypto

Can I do this?  Crypto.py can't seem to access python-crypto's Crypto
namespace, because it's own namespace takes precendence.  I tried using
the renaming trick inside of Crypto.py, but it still can't find the
original python-crypto Crypto.  Maybe there's something I can do in the
__init__.py?  Maybe something with __path__?  Is there a better way to
access namespaces from the module files themselves?

  Thanks,
  Lenny G.

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


Re: fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Thanks Michael.  That's actually what I already have, e.g.,

Hippo/
  __init__.py
  HippoCrypto.py
  Potamus.py

Of course, this has the disadvantage of not really taking advantage of
the Hippo namespace -- I might as well have:

HippoCrypto.py
Hippo/
  __init__.py
  Potamus.py

or even get rid of the namespace altogether:

HippoCrypto.py
HippoPotamus.py

Since Hippo.HippoCrypto was already in the Hippo namespace (and clearly
unambiguous with the top-level Crypto namespace from python-crypto), I
thought there might be some way to use this fact to shorten up the name
by removing the redundancy (as can be done in java/C++/etc namespaces).

It sounds like you are saying that there either isn't a way to make the
interpreter utilize this type of namespace difference, or that doing so
is so convoluted that it is certainly worse than just living with
Hippo.HippoCrypto.  I can live with these facts (with a little bit of
discomfort ;) ) -- just wanted to make sure that I understood.

  Lenny G.

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


FTP Error: Windows AS/400

2005-09-13 Thread Tim G.
I am trying to use Win Python to ftp files from an AS/400 IFS directory
down to my Windows machine.

I seem to get stuck when I am trying to send a command to the AS/400 to
switch file systems from native to IFS and then to issue a cd to my
folder.  I get the error below.

If anyone has had experience trying to ftp from a 400, I would greatly
appreciate any info on the topic.


Code:

import ftplib, os

filename=''
path = "jde7333"
os.chdir('c:\\ftp_jde400')

ftp = ftplib.FTP('test400')
ftp.login('oneworld', 'onew0r1d')
#ftp.sendcmd('quote site namefmt 1')
ftp.sendcmd('site namefmt 1')
ftp.cwd(path)
#remotefiles = ftp.nlst()
#ftp.retrlines('LIST')
#for filename in remotefiles:
#file = open(filename, 'wb')
#ftp.retrbinary('RETR ' + filename, file.write, 1024)
#file.close()

ftp.quit()


Error:

Traceback (most recent call last):
  File "C:\Python24\Tools\scripts\ftp400.py", line 10, in ?
ftp.cwd(path)
  File "C:\Python24\lib\ftplib.py", line 494, in cwd
return self.voidcmd(cmd)
  File "C:\Python24\lib\ftplib.py", line 246, in voidcmd
return self.voidresp()
  File "C:\Python24\lib\ftplib.py", line 221, in voidresp
resp = self.getresp()
  File "C:\Python24\lib\ftplib.py", line 214, in getresp
raise error_perm, resp
ftplib.error_perm: 501 Unknown extension in database file name.

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


FTP Windows AS/400

2005-09-13 Thread Tim G.
I am trying to execute a win python script that connects to an AS/400;
changes from the native lib to the IFS file system; then, changes to a
directory in IFS; gets a file.

Any help would be greatly appreciated.

I cannot get the script to switch from native to IFS.  I get the
following error:

Traceback (most recent call last):
  File "C:\Python24\Tools\scripts\ftp400.py", line 9, in ?
ftp.cwd(path)
  File "C:\Python24\lib\ftplib.py", line 494, in cwd
return self.voidcmd(cmd)
  File "C:\Python24\lib\ftplib.py", line 246, in voidcmd
return self.voidresp()
  File "C:\Python24\lib\ftplib.py", line 221, in voidresp
resp = self.getresp()
  File "C:\Python24\lib\ftplib.py", line 214, in getresp
raise error_perm, resp
ftplib.error_perm: 501 Unknown extension in database file name.

here is the script:

import ftplib, os

filename=''
path = "directory"
os.chdir('c:\\ftp_jde400')

ftp = ftplib.FTP('server', 'user', 'password')
ftp.sendcmd('site namefmt 1')
ftp.cwd(path)
#remotefiles = ftp.nlst()
#ftp.retrlines('LIST')
#for filename in remotefiles:
#file = open(filename, 'wb')
#ftp.retrbinary('RETR ' + filename, file.write, 1024)
#file.close()

ftp.quit()

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


Re: simple input that can understand special keys?

2005-02-28 Thread Tim G
Gabriel B. wrote:
> i'm writting an application that will use Tinker in a newer future.
> Now it's console only. I simply ommit some data on the display,
> print() some other and go on. The problem is that i can't test the
> actions tiggered by special keys, like Page Up/Down or the F1...12
>
> Right now i'm using raw_input() since even the Tk version will have
> only one input place, and for debuging i'm literally writting pageup,
> pagedow and the F's. But i want to put it in test while i write the
> GUI.
>
> is there any hope for me? I wanted to stay only with the console for
> now. And it's windows by the way :)
>
> Thanks

This is a notoriously un-cross-platform sort of issue.
Don't know about Tk, but for Windows, you could
use one of the existing console/curses packages:

Chris Gonnerman's WConIO:
http://newcenturycomputers.net/projects/wconio.html

The effbot's console module:
http://effbot.org/zone/console-index.htm

or a Win32 curses port:
http://flangy.com/dev/python/curses/

or you could splash out a bit and go for Pygame,
which gives you pretty much complete control over
pretty much everything:
http://pygame.org

or you could use the part-of-the-batteries mscvrt
module:
http://www.python.org/doc/2.4/lib/msvcrt-console.html


TJG

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


Re: HELP: Python equivalent of UNIX command "touch"

2005-03-03 Thread Tim G
Since no-one's suggested this yet, I highly recommend
UnxUtils: http://unxutils.sourceforge.net/ which includes
a touch.exe. Obviously, this doesn't answer your call for
a Python version, but if you're happy with touch under
Unix, maybe this will work for you.

TJG

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


newbie: dictionary - howto get key value

2005-03-10 Thread G. Völkl
Hello,

I use a dictionary:

phone = {'mike':10,'sue':8,'john':3}

phone['mike']   --> 10

I want to know who has number 3?

3 -->  'john'

How to get it in the python way ?

Thanks
   Gerhard


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


Re: os.path.islink()

2004-12-08 Thread Tim G
You may well be able to do it with the win32file module
functions: GetFileAttributesEx or GetFileInformationByHandle
It's not my area of expertise, but usually a bit of poking around
in msdn.microsoft.com yields some results, as does Googling
around for other people (often VB or Delphi-based) who have
done the same thing.

TJG

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


JSON translated into SQL by python

2013-11-22 Thread Aaron G.
I am new to programming python for JSON to SQL and I was wondering why this 
does not work. All the values for entering the DB are correct. The 
EnterpriseValue data is not entering the database.

 
#collect data from JSON source at Yahoo
url = ["db", "http://y.ahoo.it/wlB89";]
#check all sites
checkstatus(url[]);
#retrieve EnterpriseValue data from yahoo to DB
url = "http://y.ahoo.it/wlB89";
data = helper.openJSON_URL(url)
#store data
curObservation = data["EnterpriseValue"]

#connect to amazon and post data from Yahoo
conn = inti_psql_amazon("db name", "db user", "password", "db source")
query = "CREATE TABLE temp2 (ID int NOT NULL AUTO_INCREMENT, Enterprise_Value 
float, PRIMARY KEY(ID));"
query = "INSERT INTO TABLE temp2 (enterprise) VALUES("+ str(curObservation) 
+");"   
do_query_amazon(conn, query)
close_psql_amazon(conn)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread somesh g
Hi..joel

what is said is correct i dint added save to that after adding its working 
perfect

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


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread somesh g
hi..Neil 

yes i dint saved that time and i added the save option and it saved 

Thanks for the response
-- 
https://mail.python.org/mailman/listinfo/python-list


unable to read combo boxes in excel by xlrd package in python

2013-09-27 Thread somesh g
Hi..there

I want to read the combo box in excel by using "xlrd" but in the output it is 
showing empty message, its not reading the combo box can u guys help me how to 
read the combo box in excel by "xlrd"

code written like this

workbook = xlrd.open_workbook('path of the file')
worksheet = workbook.sheet_by_name('sheetname')
TargetSystem = worksheet.cell_value(4, 2)
-- 
https://mail.python.org/mailman/listinfo/python-list


How to read a particular cell by using "wb = load_workbook('path', True)" in openpyxl

2013-09-30 Thread somesh g
Hi..there

I have written code for reading the large excel files 

but my requirement is to read a particular cell in a excel file when i kept 
"True" 

in "wb = load_workbook('Path', True)"

any body please help me...

CODE:

from openpyxl import load_workbook

wb = load_workbook('Path', True)
sheet_ranges = wb.get_sheet_by_name(name = 'Global')
for row in sheet_ranges.iter_rows():
  
for cell in row: 
print cell.internal_value

Regards,
G.Someswara Rao
-- 
https://mail.python.org/mailman/listinfo/python-list


Programming Games with python, I know this subject was disccused need help

2006-08-04 Thread Over G
HI

I would like to start to program games, with python, where to start?

What packages I need,?

Thanks.

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


Re: Programming Games with python, I know this subject was disccused need help

2006-08-04 Thread Over G

Goalie_Ca wrote:
> Well, with these libraries you won't need much else.
>
> http://www.pygame.org/news.html
> and
> http://sourceforge.net/projects/pyallegro/
>
>
> Over G wrote:
> > HI
> >
> > I would like to start to program games, with python, where to start?
> >
> > What packages I need,?
> >
> > Thanks.

Thanks ofr the very quick answer!

Still can you shad more light on the second link, what is project
allegro ?

thanks/

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


Re: A problem about File path encode

2006-10-10 Thread Gabriel G

At Tuesday 10/10/2006 11:32, Kevien Lee wrote:


I agree with the problem caue of the the escape character,but when i folllow
these meth,it still didn't work.


Explain "didn't work". A full traceback would be useful.


It is so strang that the code work on another computer (OS is WinXP),but throw
error on mine.Why?plese help me


Using *exactly* the same file name? "D:\Downloads\second.xml" works 
fine too, but that's just because \d and \s are not recognised as 
escape sequences.



>   There is a problem about File path encode ,when i want to parse
> an xml file.
> xmldoc=minidom.parse("D:\Downloads\1.xml")
>IOError: [Errno 2] No such file or directory: 'D:\\Downloads\x01.xml'


--
Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

MemoryError - IMAP retrieve self._sock.recv(recv_size)

2006-10-18 Thread Stephen G
Hi there.  I have been receiving MemoryErrors using the Windows version of 
Python 2.5.  The script I have written times the sending and the reception of 
emails with various attachments.

I get many exceptions when using the IMAP downloads.  This happens randomly; 
sometimes the file downloads OK, and other times no. 

Using an exception and traceback function, I can see the following...

MemoryError

  File "C:\Documents and Settings\root\Desktop\TMO\Python 
scripts\imap-v2.3a.py", line 263, in main
typ, data = M.fetch(num, '(RFC822)')

  File "C:\Python25\lib\imaplib.py", line 437, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)

  File "C:\Python25\lib\imaplib.py", line 1055, in _simple_command
return self._command_complete(name, self._command(name, *args))

  File "C:\Python25\lib\imaplib.py", line 885, in _command_complete
typ, data = self._get_tagged_response(tag)

  File "C:\Python25\lib\imaplib.py", line 986, in _get_tagged_response
self._get_response()

  File "C:\Python25\lib\imaplib.py", line 948, in _get_response
data = self.read(size)

  File "C:\Python25\lib\imaplib.py", line 236, in read
return self.file.read(size)

  File "C:\Python25\lib\socket.py", line 308, in read
data = self._sock.recv(recv_size)

Is this a know bug or is there something I can do to work around this?

Thanks,

Stephen


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


Re: MemoryError - IMAP retrieve self._sock.recv(recv_size)

2006-10-18 Thread Stephen G
Fredrik,

Thanks for the response.  I did see that, but having been dated 2005 I thought 
that it might have been patched.  I am also sometimes getting the same problem 
with the urllib.py module.  T

his may have to do with the interaction between Python and the mobile 
optimization client that I am testing.  I do not see this problem when using 
Internet Explorer and the optimization client, nor is there a problem when 
using Python and no optimization client.  I am working with the optimization 
client vendor to have them test my Python script with their product.  This 
problem is intermittent with the optimization client which is annoying since 
most of the time it works.

Iteration Number 12
18/10/2006 14:01:23
Downloading http://tmotest.de/ftp/3MB.doc
Error: problem downloading 3MB.doc

error

  File "C:\Documents and Settings\root\Desktop\TMO\Python 
scripts\http-v2.3a.py", line 130, in main
urllib.urlretrieve(total_URL, downloaded_file)

  File "C:\Python25\lib\urllib.py", line 89, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)

  File "C:\Python25\lib\urllib.py", line 248, in retrieve
block = fp.read(bs)

  File "C:\Python25\lib\socket.py", line 308, in read
data = self._sock.recv(recv_size)

I am hesitant to make any changes to the python libraries as I need to 
distribute these scripts with a standard Python install.  I guess an other 
option is to try and learn something like Perl and recode all the test 
scripts...
 


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


Re: "best" rational number library for Python?

2006-10-31 Thread Gabriel G

At Tuesday 31/10/2006 21:16, [EMAIL PROTECTED] wrote:


casevh> You must use "gmake". "make" fails during "make check"

Very weird:

piggy:% make -v
GNU Make 3.80
piggy:% gmake -v
GNU Make 3.80

Nevertheless, using "gmake" instead of "make" did indeed work.  Thanks for
the hint.


Ouch! Like bash behaving different when invoked with the name "sh". 
Why do those programs try to be s smart?



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: unpickling Set as set

2006-11-08 Thread Gabriel G

At Wednesday 8/11/2006 05:26, George Sakkis wrote:


Or you may have this done automatically by hacking the Set class:

from sets import Set
import cPickle as pickle

Set.__reduce__ = lambda self: (set, (self._data,))

s = Set([1,2,3])
x = pickle.dumps(s)
print pickle.loads(x)


This doesn't work though if you have already pickled the Set before
replacing its __reduce__, so it may not necessarily be what you want.
If there is a way around it, I'd like to know it.


Perhaps registering a suitable reduce function in the copy_reg module.
If the sets were pickled alone, and it's not too much trouble, using: 
a_set = set(a_set) just after unpickling may be enough.
And if they were instance attributes, __setstate__ on the class can 
do the conversion.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: is this the right way to do subclasses?

2006-11-08 Thread Gabriel G

At Wednesday 8/11/2006 16:33, John Salerno wrote:


> class Character(object):
> def __init__(self, name, strength, dexterity, intelligence):
> self.name = name
> self.health = 10
> self.strength = strength
> self.dexterity = dexterity
> self.intelligence = intelligence
> self.fix_attributes()
>
> class Fighter(Character):
> def fix_attributes(self):
> self.health += 2
> self.strength += 1
>
> You may need a no-op implementation of fix_attributes() in the Character
> class.
>
> Peter

But how does this take care of the initialization of the stats? I won't
be able to use Fighter to create a character without doing everything in
Character, right?


Just try and see! :)
(Python is not Java, thanks Guido!)


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python to tell what is the IP of my PC .

2006-11-08 Thread Nicolas G
On 11/9/06, Tim Williams <[EMAIL PROTECTED]> wrote:
On 8 Nov 2006 15:35:31 -0800, NicolasG <[EMAIL PROTECTED]> wrote:> How can I use python to get the real IP address of my DSL router (when> my PC is part of the local home LAN) ?
The router will the PC's default gateway IP address,  if you are on awindows platform,  you can view it by typing IPCONFIG (enter) from acommand prompt.This is the  router local IP, I need to get the router "outside" IP witch is the real one. 
A quick google, gave me this,  look at the comments at the end for anexample of finding the Default Gateway IP address using Python
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/162994import
 win32api raise the error "module not exsit"and socket.gethostbyname(name)the router doesn't have a hostname.cheers ;)-- Nicolas GSkype: nicolasg_
mobile: +30 69 45 714 578
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how do i map this?

2006-11-12 Thread Gabriel G

At Monday 13/11/2006 01:55, John Machin wrote:


Ben Finney wrote:
> "ronrsr" <[EMAIL PROTECTED]> writes:
>
> > #row is a dictionary with keys: zid, keywords, citation, quotation
> > def print_row(row):
> >print """
> >   [...]
> >   """
>
> You're printing a string, and never using that 'row' parameter.

If that is so, why is he getting that message "TypeError: format
requires a mapping"?


Apparently the posted code doesn't match the actual code. If that 
print_row() matched the stack trace, should say % row at the end.

Perhaps there is another function print_row?
Or you cut something from the end?


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: lazy arithmetic

2006-08-24 Thread Gabriel G

At Friday 25/8/2006 02:18, [EMAIL PROTECTED] wrote:


> x+y get translated to x.__add__(y)

No that's not true at all. The self argument to __add__ ends
up being the Add instance, not the Item instance:

z=x+y  is translated to z.__add__(y)


Well, I deleted my response after I noticed that Simon Forman has 
done it very well.
Just a note: print z after this line and compare with self inside 
__init__ if you're still not convinced.




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: question about class, functions and scope

2006-08-28 Thread Gabriel G

At Saturday 26/8/2006 06:13, nephish wrote:


i have an app that runs three classes as threads in the same program.
some of them need to be able to share some functions. Can i set a
function before i define a class and have the class use it ? Kinda like
this.

def some_function(var1, var2):
do something with var1, var2
return result


It's ok - but beware of concurrency problems. By example, two threads 
trying to update the  same thing. (Doesn't happen in your small example).




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Python web service ...

2006-08-28 Thread Nicolas G
If I want to run my program as a web service I need to setup a
webserver , am I right ?
Whars that difference ? can a webservice be run without a webserver ?

On 8/29/06, Jorge Vargas <[EMAIL PROTECTED]> wrote:
> On 26 Aug 2006 04:07:35 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Hi folks, I have accomplished to make a python program that make some
> > image manipulation to bmp files.
> > I now want to provide this program as a web service. A user can visit a
> > site and through a web interface he should upload the file to the web
> > server , the server then will do the image process with the python
> > program I have wrote and when it finish the user must get the image
> > file back .
> >
> > My question is how difficult is to set up a web server that can run
> > python easy ? should I try ZOPE or there is something better in mind ?
>
> is that webservice or webserver?
> if webservice try ZSI of it's a webserver why don't you try CherryPy?
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>


-- 
Nicolas G

mobile: +30 69 45 714 578
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a question about my script

2006-08-31 Thread Gabriel G

At Thursday 31/8/2006 10:01, alper soyler wrote:


I changed the script as you wrote below:


directory = 'pub/kegg/genomes'


Sorry, in the original comment I said "change it to be an absolute 
path" but didn't write it well.

This line should read:
directory = '/pub/kegg/genomes'



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: a question about ftplib

2006-09-01 Thread Gabriel G

At Friday 1/9/2006 06:32, alper soyler wrote:

Thank you very much for your help. The program works however, after 
downloading 121 '.pep' files, it gave me time out error:


Traceback (most recent call last):
  File "ftp1.0.py", line 18, in ?
for filename in ftp.nlst():
  ...
  File "/usr/lib/python2.4/ftplib.py", line 324, in ntransfercmd
conn.connect(sa)
  File "", line 1, in connect
socket.error: (110, 'Connection timed out')

How can I continue from the last download or  is there any way to 
arrange the time? Thank you very much.


You can change the default timeout for sockets with 
socket.setdefaulttimeout(secs) (this is a module function; call it at 
the beginning of your script).
To continue from the last download, you could skip downloading files 
when they already exist on your disk: before opening it for write, 
use os.path.exists(full_filename) to detect it, and skip the download part.


If you want to continue even after an exception happens, use the 
try/except syntax.

I don't have your code at hand to show the details, but it was something like:

for directory in dirlist:
cwd(directory)
for filename in directory:
download file

You may want to change it to:

for directory in dirlist:
try:
  cwd(directory)
  for filename in directory:
if (filename already exists): continue
try:
  download file
except: print '%s: %s' % sys.exc_info()[:2]
except: print '%s: %s' % sys.exc_info()[:2]

This way, if an error happens within downloading a file, goes on the 
next; and if an error happens procesing a directory, goes on the next too.
As a general guide, bare except clauses (that is, without a matching 
exception class) are not good, but for an utility script like yours I 
think it's fine.



Gabriel Genellina
Softlab SRL  






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: A critique of cgi.escape

2006-09-25 Thread Gabriel G

At Monday 25/9/2006 11:08, Jon Ribbens wrote:


>> What precisely do you think it would "break"?
>
> existing code, and existing tests.

I'm sorry, that's not good enough. How, precisely, would it break
"existing code"? Can you come up with an example, or even an
explanation of how it *could* break existing code?


FWIW, a *lot* of unit tests on *my* generated html code would break, 
and I imagine a *lot* of other people's code would break too. So 
changing the defaults is not a good idea.
But if you want, import this on sitecustomize.py and pretend it said 
quote=True:


import cgi
cgi.escape.func_defaults = (True,)
del cgi



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: A critique of cgi.escape

2006-09-26 Thread Gabriel G

At Tuesday 26/9/2006 04:16, Lawrence D'Oliveiro wrote:


>> >> What precisely do you think it would "break"?
> FWIW, a *lot* of unit tests on *my* generated html code would break...
Why did you write your code that way?


Uhm, maybe because I relied on the published documentation of a 
published standard module? Just modify the behavior in *your* own 
cgi.escape and all of us will be happy...




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: A critique of cgi.escape

2006-09-26 Thread Gabriel G

At Tuesday 26/9/2006 12:53, Jon Ribbens wrote:


> BTW, I am curious about how you do unit testing. The example that I used
> in my summary is a very common pattern but would break in cgi.escape
> changed it's semantics. What do you do instead?

To be honest I'm not sure what *sort* of code people test this way. It
just doesn't seem appropriate at all for web page generating code. Web
pages need to be manually viewed in web browsers, and validated, and
checked for accessibility. Checking they're equal to a particular
string just seems bizarre (and where does that string come from
anyway?)


By example, I do not validate a "page". I validate that all methods 
that make up pieces of a page, build them the way they should - these 
are our "unit tests". Then, it's up to the templating library to join 
all the pieces into the final html page.
I validated the original html against the corresponding dtd some time 
ago (using the w3c validator), and ocasionally when things "looks 
wrong" on a browser, but most of the time the html generated pages 
are not validated nor checked as a whole.
What you describe are another kind of tests, and really should not 
depend on the details of cgi.escape - as the usability test of an MP3 
player does not care about some transitor's hFE used inside...




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread Gabriel G

At Thursday 28/9/2006 12:23, Ramon Diaz-Uriarte wrote:


Going back to the original question, a related question: does anybody
know why there are so few books on data structures and algorithms that
use Python?

I remember that, at least ~ 12 years ago there were many (and very
good) books that used Pascal for this topic. So when I did my own
search for one in Python (just for my own consumption and
enlightnment) and could only find the same one as the original poster
of this thread [1], I was very surprised. No publishers have felt the
need to fill this gap?


Maybe, because with Pascal you got *nothing* more than the bare 
language, and you had to implement most of the structures and 
algorithms yourself. (This was by design).
Python, on the other hand, comes with "batteries included". What's 
the point in reimplementing another mapping/dictionary structure 
using Python, having the built-in dict type which is rather efficient?
I would not use Python to teach *basic* data structures, instead, I'd 
use it as a second stage to teach more complex structures and how to 
design algorithms.



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: where the extra space comes from on the stdout

2006-10-02 Thread Gabriel G

At Saturday 30/9/2006 19:09, Steve Holden wrote:


> while 1:
>  print 'Question [Y/[N]]?',
>  if sys.stdin.readline().strip() in ('Y','y'):
>  #do something
>  pass
>
> $ python q.py
> Question [Y/[N]]?y
>   Question [Y/[N]]?y
>   Question [Y/[N]]?y
>
Yup. When you execute a print statement with a comma at the end it
doesn't output the space, it simply sets a flag reminding it that there
should be a space before the next item on the same line. If the next
character out is a newline then the space flag is reset, but in this
case the newline was provided by the input, so you get a space at the
start of the next output.


You could try using
print '\rQuestion?',


Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: saving an exception

2006-10-03 Thread Gabriel G
At Tuesday 3/10/2006 02:15, Bryan wrote:

>i would like to save an exception and reraise it at a later time.
>def foo():
>Â  Â  try:
>Â  Â  Â  Â  1/0
>Â  Â  except Exception, e:
>Â  Â  Â  Â  exception = e
>
>if exception: raise exception
>
>with the above code, i'm able to successfully raise the exception, but the
>line number of the exception is at the place of the explicit raise instead
>of the where the exception originally occurred. Â is there anyway to fix
>this?

The raise statement has 3 arguments, the third 
being the traceback (not used so much, except in cases like yours).
You can get the values using sys.exc_info()
(Don't store the traceback more than needed 
because it holds a reference to all previous stack frames...)


Gabriel Genellina
Softlab SRL 





__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas

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


Re: Howto pass Array/Hash into Function

2006-10-03 Thread Gabriel G

At Tuesday 3/10/2006 06:05, Wijaya Edward wrote:


How can I pass Array, Hash, and a plain variable
in to a function at the same time.

I come from Perl. Where as you probably know
it is done like this:

sub myfunc {

my ($plain_var, $hash_ref,$arref) = @_;
# Do sth with those variables

   return;
}


In Python your functions have formal arguments:

def myfunc(plain_var, some_dict, some_list):
# ...
return

You also have positional and keyword arguments, and default values. 
Read the Python tutorial 




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: PEP 358 and operations on bytes

2006-10-03 Thread Gabriel G

At Tuesday 3/10/2006 21:52, Ben Finney wrote:


Gerrit Holl <[EMAIL PROTECTED]> writes:

> operations that aren't currently defined in PEP 358, like:
>
> - str methods endswith, find, partition, replace, split(lines),
>   startswith,
> - Regular expressions
>
> I think those can be useful on a bytes type. Perhaps bytes and str
> could share a common parent class? They certainly share a lot of
> properties and possible operations one might want to perform.

Looking at those, I don't see why they wouldn't be useful for *all*
sequence types. Perhaps there needs to be a 'seq' type containing
those common methods, that is the superclass of 'str', 'bytes',
'list', 'tuple' et cetera.


find() could be useful sometimes.
But what means partition, replace, split, etc on a generic sequence?



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Python Question About Compiling.

2006-11-29 Thread Gabriel G

At Thursday 30/11/2006 03:40, Scheol Service wrote:


i know this. Is there better directions on how to use it?


Have you tried it? What's your actual problem? See http://www.py2exe.org/


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: One detail...

2006-12-01 Thread Gabriel G

At Saturday 2/12/2006 00:40, [EMAIL PROTECTED] wrote:

I'm trying to do in Zope, which doesn't allow "_" characters at the 
beginning of identifiers. Even in an external method, it gives me an 
error when I try to reference the o.a. Is there a trick to do it 
some other way?


Better to ask on a Zope group.
But why do you want to do that? As you have noticed, you must provide 
security assertions for your objects so it's not an easy way. And 
dictionaries are fully supported by ZPT and DTML - as it appears to 
be what you want.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

cgi - secure sessions

2006-02-01 Thread infini . g
Hey,

I was just wondering if / how would it be possible to create secure
sessions for a website using Python CGI... I thought of using cookies,
and things looked promising for a while; I could login through a form
which pointed to a cgi script which created sent the user cookies, but
I found that when a script to detect the cookies was run through a
server side include line in the html, it couldn't get any cookies, but
it would work fine when run directly through the browser (which is
useless to me).

If anybody could help with this it would be great. Python is the only
programming language that I'm relatively comfortable in at the moment,
so using the usual PHP or Javascript just isn't an option for me
unfortunately.

GazaM

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


Checkbuttons in a Text widget

2006-02-17 Thread Lou G
I'm trying to show a number of Checkbuttons (each with associated text
based on a list of names) inside a y-scrollable Text widget like so:

[ ] Bob
[ ] Carol
[ ] Ted
[ ] Alice
etc.
etc.

There may be quite a few (as many as 100 or so). I'm uncertain as to
the correct way to get these into the Text widget. I've tried
text.insert and it doesn't seem to do the job. Help?

Thanks,
Lou G

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


Re: Checkbuttons in a Text widget

2006-02-17 Thread Lou G
For anyone who might be able to use this technique:
I kept playing around and got it to work:

for i in nameList:
btnText = name[i]
self.sv = []
cb = []
cb.append(Checkbutton(self.datalist, text=btnText,
variable=self.sv[i], background='white', font=("Courier", 10)))
self.datalist.window_create(INSERT, window=cb[i])
self.datalist.insert(END, '\n') 

Thank you for your replies,
Lou

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


Looking for Pythonic Examples

2006-02-28 Thread G. Völkl
Hello 

I am looking for examples of Pythonic Thinking:

One example I found:

Here some lines of the web side of Bruce Eckel:
http://www.mindview.net/WebLog/log-0053

How to read a text file:
for line in file("FileName.txt"):
  # Process line
It is a easy and sophisticated thing in python,
but hard to do or more complicated in other languages 
like java.

Does anyone know more examples ?

Does anyone know books about real good python programming ?

Best Regards

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


Re: HELP Printing with wxPython

2005-05-11 Thread Tim G
> Hello all, I'm trying hard to make possible to print some simple text
from
> python to the default printer using wxPython, after days of internet
> searches I found this page:
http://wiki.wxpython.org/index.cgi/Printing but
> is impossible to use this script even if I do exactly as said there.
I think
> the script is buggy or I am not able to use it, even if seems very
simple to
> use...
>
> Anyone can give me an hint on how to easily and simply print some
text? Is
> there a library ready to download and use? Something like
SendPrinter("some
> text\n")?

On the strict wxPython front, I can't help
you, but I might be able to offer some help.
Depends a little bit on how much you're tied
to wxPython and how much you need to be cross-platform.

Essentially, if you're on Windows (and have no need
to run on anything else) then consider some of the
solutions here:

http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html

If you're on Unix / whatever with no need to do
anything else, then I'm sure there are straightforward
ways to push stuff to a printer. (Something using lpr
he thinks, hoping someone with real knowledge can chip
in).

If you *really* want to use wxPython for cross-platform
needs, or just because you think it's cleaner, then try
on the wxPython lists if you haven't already.

TJG

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


Python and Java

2007-04-04 Thread Sreelatha G

Hi

  I am new to python .I need your help in solving my problem.
  Is there any way to call python files in a java file .How is it possible?


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

Re: *POLL* How many sheeple believe in the 911 fairy tale and willing to accept an Orwellian doublespeak and enslavement world ?

2007-01-17 Thread Carl G.

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
...

Please explain what 911 conspiracy theories have to do with the Python 
computer language?

If this is to be taken seriously, why is it being cross-posted to sci.math, 
sci.physics, sci.chem, sci.optics, and comp.lang.python?  Such blatant 
disregard for newsgroup etiquette will surely reflect poorly on the poster's 
credibility.  I can only draw the conclusion that he is either a troll or 
very ignorant of what is acceptable.

Carl G. 


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


memory leak

2007-01-26 Thread john g

i have a memory leak issue with extension function that im working on. it
reads data from a binary file into a stl vector then creates a new list to
pass back to the python interface. the function works the first 1021 times
but then gives a segmentation fault (core dumped). heres the business part
of the code:


//read data
   vector data;
   float temp;


   for(int x=0;x-- 
http://mail.python.org/mailman/listinfo/python-list

get pid of a nohup command in Python

2007-02-12 Thread g . willgoose
I'm new to Python and am evaluating moving a project from Tcl/Tk to
Python and am stuck on one issue. How can I nohup (or any detached
task for that matter) a process and get its PID in Python. The obvious
route of (with a trivial example)

os.system("nohup ls > junk &")

returns the status of the command execution (ie. 0). I wish to get the
PID output of the command (e.g. 16617). All the other commands spawn**
also seem to return the execution status not the PID. This is a
showstopper so any help appreciated.

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


Re: Can Python installation be as clean as PHP?

2006-05-09 Thread G. Monzón
Please don't compare PHP with Python... They are very different worlds.

Maybe not all the Python's core functions are implemented in C, but
Python is really a lot more efficient than PHP in every case you want
to compare.

If you "look inside", there's nothing to compare... they are extremely
different worlds... they are like hell and heaven, from the awesome
brilliant C Python implementation, to the ugly C PHP hack... (after all
it is my personal opinion, I've worked with PHP for more than 4 years,
for websites and console scripting).

Python is more efficient than PHP in every aspect...  I don't know why
got (and still is) so popular, IMHO Python should have taken its place
as the best "web scripting language".

OTOH, my php install have lots more than a single executable file.
Perhaps you don't use any php extension? don't think so... do you use
pear? and pecl? you need lots of files too, and until you don't know
what do they are and what you need or not, you will be in the same
issue as you're with Python. I think you will get it early, as you
find everything is more straightforward than you thought.

Gonzalo Monzón.

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


Re: Can Python installation be as clean as PHP?

2006-05-09 Thread G. Monzón

Carl Banks wrote:
> G. Monzón wrote:
> > Please don't compare PHP with Python... They are very different worlds.
>
> I'm not.  I was simply agreeing that the single executable way the OP
> claimed PHP does it can *sometimes* be preferrable in Python, and
> giving him recommendations thereto.
>
> Carl Banks

Sorry Carl, my reply was for the OP. I pressed the wrong reply
button... doesn't meant you did any comparation!

I said that about comparing, as the OP thought Python coded in Python
approach for a lot of core libraries isn't as efficient as in PHP
'cause they are all coded in C. And that's not true.

Yes, it could be obvious for some people that it "should" run faster
than Python, having all core functions coded in C, yes, but in overall
performance matters, that's not true in any case.

Python has all the primitives C coded as said in this thread. PHP
"primitives" are no more than hash-tables and lots zvals... far away
from the hi-tuned advanced data-types Python exposes. That makes a big
performance improvement over PHP, regards C or Python coded core
functions -let language implementation details apart-. Major loss of
performance in Python and PHP is on translating data values to C side
and all the functions calling done for as little as a value assignment
to a variable. So, sometimes, to code a function in C or let it be
Python, makes no more than a 1us per call difference...
I'd like to see this value compared to PHP. That's why PHP need a C
implementation for all core functions, as if they would be PHP coded,
performance would be even a lot worse.

And I would't say PHP is slow. But It depends on what you need to do.
'Cause PHP can be really slow and ultra-high memory consuming. While
you had this troubles with PHP, is nice to see how Python performs:
consumes a lot less of memory and goes 50 % more fast.

About a single executable file, I thought PHP is being distributed in
windows and linux as an executable plus an dinamic link library, that's
the minimum thing you need to run scripts. So OP is wrong, there is not
a single executable file. You need two files at least + php.ini +
extensions to run almost any PHP script.

And a PHP or Python without extensions or batteries, wouldn't be very
handy... oh well, that depends on the task to do.

Anyway, PHP isn't a bad tool for a *lot* of web-side scripting, but I'd
prefer if I could use Python in many of my work projects. :-) I'd feel
happier !

Regards,
Gonzalo.

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


Re: Incrementally converting a C app to Python

2006-05-09 Thread G. Monzón
Hi Bjorn,

I think the best approach is highly-dependent to your current C
application design and "way of doing things". For a type of application
you would take the opposite path than for other I thought.

Yes I did that one time, but I re-coded all from scratch... and since
that I usually do in reverse: code in Python, then optimize if needed
in C via pyrex coded extensions and glue.

If you don't know well the current application internals, both
approaches can be harder: to convert step by step to python or
re-implement from scratch. You need to know well what is doing there
that pretty hard to read code for being sure for success and good
starting guidelines.

I thought If your app doesn't have very critical parts, and if you
really know what the application is doing "inside", I would bet for a
complete reimplementation from scratch. More if you say current C code
has a lots of bugs! And all the code you need to be in C, can be easily
done via pyrex, ctypes, etc. Have in mind I don't know your
application!

Swig is harder, is more suited to export whole libraries to between
languages. Anyway, I'm no expert with Swig! :-)

Regards,
Gonzalo Monzón.

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


hidden file detection

2006-05-19 Thread Lenny G.
What's the best way to do cross-platform hidden file detection?  I want
to do something like weed-out the files that should be 'hidden' from
os.listdir() (which would be files that start with '.' under Unix,
files that have the hidden attribute set on windows, and whatever it is
that makes Mac files hidden).  Is there a util or lib that does this
for me?

Thanks,
Gary

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


wxPython graphics query (newbie)

2008-03-17 Thread Thomas G
I am exploring wxPython and would be grateful for some help.

It is important to me to be able to slide words and shapes around by 
dragging them from place to place. I don't mean dragging them into a 
different window, which is what 'Drag and Drop' has come to mean, just 
moving them around within a canvas-like space.

This is easy using Tkinter. Can anybody offer me a tiny, very simple 
example of how it would be done in wxPython, please?

To make sure I convey what I'm looking for, here is what it looks like 
using Tkinter, written very simply. What I'm looking for is the same, 
quite simple functionality expressed in wxPython, again written very 
simply so that I can easily understand it.



#!/usr/bin/python
from Tkinter import *

root = Tk()

global canv


def makeFrame(root):
   global canv
   canv = Canvas (root, height = 200, width = 350)
   canv.create_text(100, 100, text='drag me', tags=('movable'))
  
   canv.tag_bind('movable', '', slide) #B1-motion is a drag 
with left button down
   canv.pack()

def slide (event):
   '''
   triggered when something is dragged on the canvas - move thing under 
mouse ('current') to new position
   '''
   newx = event.x
   newy = event.y
   canv.coords('current', newx, newy)

makeFrame(root)
root.mainloop()


Many thanks in advance

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


Re: Ideas to optimize this getitem/eval call?

2009-01-22 Thread mario g
On Sun, Jan 4, 2009 at 6:46 PM, Tino Wildenhain  wrote:
> mario wrote:
>>
>> On Jan 3, 7:16 am, Steven D'Aprano > cybersource.com.au> wrote:
>>
>>> I was about to make a comment about this being a security hole,
>>
>> Strange that you say this, as you are also implying that *all* the
>> widely-used templating systems for python are security holes... Well,
>> you would be right to say that of course ;-) Infact, evoque is really
>> one of the few (or even the only one?) that was conceived from the
>> start to support restricted evaluation.
>
> Thats is definitively not the case. There are at least 2 quite old
> template systems on top of a quite good restricted environment.

Interesting, which ones?

I should have probably emphasized *conceived* above... that feature
was there in the initial design and not added afterwards.

> Cheers
> Tino
--
http://mail.python.org/mailman/listinfo/python-list


Control a process interactively (pexpect) and save data

2009-05-06 Thread Piotrek G.

Hi,

I'm trying to use something like pexpect.interact() but I want to save 
all my inputs and save all outputs from the process (/bin/sh Linux).
The main goal is to record all sequence of commands and responses in 
order to automatically generate pexpect script.


My script is like below so far, but I'm unable to print responses to 
stdout and save it to variables/files/whatever.


p = pexpect.spawn('/bin/sh')
print "PID: " + str(p.pid)
p.logfile = sys.stdout
while True:
if not p.isalive():
print "Not alive"
break
else:
print "Alive!"
p.flush()
bb = sys.stdin.readline()
p.sendline(bb)
sys.exit(0)

pexpect.interact() doesn't allow to save input and output.

I tried pipes but I've found that "Don't use a pipe to control another 
application..." - http://edgysoftware.com/doc/python-pexpect/doc/


I tried subprocess module but it didn't allow me to control /bin/sh as 
communicate() method do as follows
"Interact with process: Send data to stdin. Read data from stdout and 
stderr, until end-of-file is reached. Wait for process to terminate. The 
optional input argument should be a string to be sent to the child 
process, or None, if no data should be sent to the child."


So it "waits for process to terminate" and I'm unable to interact...

Any suggestions?

Oh, and by the way my script works with /bin/sh but doesn't work with 
/bin/bash. If I enter 'exit' sh exits, bash does not... Why?


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


Python 3000 vs Perl 6

2008-06-23 Thread Corey G.
If Perl 6 ever does get on its feet and get released, how does it  
compare to Python 3000?  Is Perl 6 more like Java now with Parrot?  I  
just want to make sure that Python is staying competitive.


If this is the wrong mailing list, just let me know.  Thanks!


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


Re: Python 3000 vs Perl 6

2008-06-24 Thread Corey G.
What I meant, in terms of dealing with accurate or non-accurate rumors  
is with speed, yes.  There are plenty of comparisons where Perl is  
4-15x faster then Python for 'some' operations regarding regular  
expressions, etc.


For me personally, this means absolutely nothing because if I spend  
50x more time comprehending spaghetti, obfuscated Perl code it's  
irrelevant.  The main concern (my concern) is whether or not Perl 6 is  
more like Java with pre-compiled byte code (did I say that right) and  
whether or not individuals without the ability to see past the surface  
will begin to migrate towards Perl 6 for its seemingly faster  
capabilities.


With Perl 6 taking 10+ years, if/when it actually gets released, will  
it be technically ahead of Python 3000?  Is Parrot worth the extra  
wait the Perl 6 project is enduring?  My own answer would be a  
resounding no, but I am curious as to what others think. :)


-Thanks!





On Jun 24, 2008, at 2:52 AM, [EMAIL PROTECTED] wrote:


On Jun 24, 8:20 am, "Corey G." <[EMAIL PROTECTED]> wrote:

If Perl 6 ever does get on its feet and get released, how does it
compare to Python 3000?  Is Perl 6 more like Java now with Parrot?  I
just want to make sure that Python is staying competitive.

If this is the wrong mailing list, just let me know.  Thanks!


Do you mean in terms of speed (parrot is a JIT?). I believe Python 3k
will (when out of beta) will have a speed similar to what it has
currently in 2.5, possibly with speed ups in some locations. But
competitive-wise I think the point is Python 3k tries to remove warts
from the Python Language to make it even more friendly to readers and
writers alike. In that way it should/will stay competitive.

However towards overall usage, the general advice is to stay with the
2.x series for now, trying to ensure your code style is moving towards
the Py3k style, and then make the jump to the 3.x series when it is
finialised.

Another point, is Perl 6 ever going to get released :P
--
http://mail.python.org/mailman/listinfo/python-list



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


  1   2   3   4   >