linregress and polyfit

2013-09-17 Thread Krishnan
I created an xy pair

y = slope*x + intercept

then I added some noise to "y" using

numpy.random.normal - call it z 

I could recover the slope, intercept from (x,y) using linregress
BUT cannot calculate the slope, intercept from (x, z)

What is puzzling is that for both pairs (x,y) and (x,z) the
polyfit (order 1) works just fine (gives me the slope, intercept)
--
import numpy as np
import scipy
# create a straight line, y= slope*x + intercept 
x = np.linspace(0.0,10.0,21)  
slope = 1.0  
intercept = 3.0   
y = []  
for i in range(len(x)):  
y.append(slope*x[i] + intercept)  
# now create a data file with noise
z= []  
for i in range(len(x)):  
z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1))  
# now calculate the slope, intercept using linregress
from scipy import stats  
# No error here this is OK, works for x, y
cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y)
print cslope, cintercept
# I get an error here
#ValueError: array dimensions must agree except for d_0
nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z)  
print nslope, nintercept
# BUT polyfit works fine, polynomial or order 1 with both data sets
ncoeffs = scipy.polyfit(x,z,1)  
print ncoeffs
coeffs = scipy.polyfit(x,y,1)  
print coeffs
-- 
https://mail.python.org/mailman/listinfo/python-list


your web page details

2011-03-29 Thread radha krishnan
 http://123maza.com/65/agent409/
-- 
http://mail.python.org/mailman/listinfo/python-list


Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread H Krishnan
Hi,

I am working on embedding Python in my application. I have redirected
sys.stdin and sys.stdout to call methods from a Qt TextEdit widget.
Everything works fine except that the Python prompt does not always come in
a new line:

>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']>>>

Why doesn't the prompt appear in a new line as with the default stdout?

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


Re: Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-05 Thread H Krishnan
Thanks for your help.

>
> >
> > I am working on embedding Python in my application.
>
> You forgot to tell us the version of Python that you're embedding.
>
> I am using Python2.7.


> > I have redirected sys.stdin and sys.stdout to call methods from a Qt
> TextEdit
> > widget. Everything works fine except that the Python prompt does not
> always
> > come in a new line:
> >
> >>>> dir()
> > ['__builtins__', '__doc__', '__name__', '__package__']>>>
> >
> > Why doesn't the prompt appear in a new line as with the default stdout?
>
> Are you using code.InteractiveConsole / code.interact?
>
> I am using code.InteractiveConsole().interact().


> If not, in what mode do you compile, Py_file_input ("exec") or
> Py_single_input ("single")? The latter executes PRINT_EXPR:
>
> >>> dis.dis(compile('1', '', 'single'))
>   1   0 LOAD_CONST   0 (1)
>   3 PRINT_EXPR
>   4 LOAD_CONST   1 (None)
>   7 RETURN_VALUE
>
> PRINT_EXPR in turn calls sys.displayhook on the value it pops from the
> stack. The default hook writes the repr of the value and a newline to
> sys.stdout, and it also references the value as "_" in the builtins
> module (2.x __builtin__).
>

I tried replacing sys.displayhook with a function that does not print
newline but the newline still got inserted. So, I am not sure where the
newline is coming from. In any case, I could override sys.displayhook to
add a newline at the end and that seems to resolve my problem.


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

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


Re: Forcing prompt to be on newline when embedding Python with stdin/out redirection

2017-01-06 Thread H Krishnan
Hello Mr.Eryk,

Thanks for the detailed explanation. After I added attribute support to my
extension class for stdio, the problem was resolved.

Regards,
Krishnan


On Fri, Jan 6, 2017 at 9:24 AM, eryk sun  wrote:

> On Fri, Jan 6, 2017 at 1:06 AM, H Krishnan  wrote:
> > I tried replacing sys.displayhook with a function that does not print
> > newline but the newline still got inserted. So, I am not sure where the
> > newline is coming from. In any case, I could override sys.displayhook to
> add
> > a newline at the end and that seems to resolve my problem.
>
> In Python 2 the newline is written depending on the value of
> sys.stdout.softspace. sys.displayhook initially calls Py_FlushLine,
> which resets the file's softspace to 0 via PyFile_SoftSpace and writes
> a newline if the previous value was non-zero. Next displayhook writes
> the repr, sets the softspace to 1 and calls Py_FlushLine again.
>
> The result you're seeing could occur if your filelike object doesn't
> have a dict or a property to allow setting the "softspace" attribute,
> as the following toy example demonstrates:
>
> import sys
>
> class File(object):
> def __init__(self, file):
> self._file = file
> self._sp_enabled = True
> self.softspace = 0
>
> def write(self, string):
> return self._file.write(string)
>
> def __getattribute__(self, name):
> value = object.__getattribute__(self, name)
> if name == 'softspace':
> if not self._sp_enabled:
> raise AttributeError
> self._file.write('[get softspace <- %d]\n' % value)
> return value
>
> def __setattr__(self, name, value):
> if name == 'softspace':
> if not self._sp_enabled:
> raise AttributeError
> self._file.write('[set softspace -> %d]\n' % value)
> object.__setattr__(self, name, value)
>
> softspace enabled:
>
> >>> sys.stdout = File(sys.stdout)
> [set softspace -> 0]
> [get softspace <- 0]
> [set softspace -> 0]
> >>> 42
> [get softspace <- 0]
> [set softspace -> 0]
> 42[get softspace <- 0]
> [set softspace -> 1]
> [get softspace <- 1]
> [set softspace -> 0]
>
> [get softspace <- 0]
> [set softspace -> 0]
>
> softspace disabled:
>
> >>> sys.stdout._sp_enabled = False
> >>> 42
> 42>>> 42
> 42>>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Forcing prompt to be on newline when embedding Python with

2017-01-06 Thread H Krishnan
Hello Mr.Eryk,

Thanks for the detailed explanation. After I added attribute support to my 
extension class for stdio, the problem was resolved.

Regards,
Krishnan


On Fri, Jan 6, 2017 at 9:24 AM, eryk sun  wrote:

> On Fri, Jan 6, 2017 at 1:06 AM, H Krishnan  wrote:
> > I tried replacing sys.displayhook with a function that does not print
> > newline but the newline still got inserted. So, I am not sure where the
> > newline is coming from. In any case, I could override sys.displayhook to
> add
> > a newline at the end and that seems to resolve my problem.
>
> In Python 2 the newline is written depending on the value of
> sys.stdout.softspace. sys.displayhook initially calls Py_FlushLine,
> which resets the file's softspace to 0 via PyFile_SoftSpace and writes
> a newline if the previous value was non-zero. Next displayhook writes
> the repr, sets the softspace to 1 and calls Py_FlushLine again.
>
> The result you're seeing could occur if your filelike object doesn't
> have a dict or a property to allow setting the "softspace" attribute,
> as the following toy example demonstrates:
>
> import sys
>
> class File(object):
> def __init__(self, file):
> self._file = file
> self._sp_enabled = True
> self.softspace = 0
>
> def write(self, string):
> return self._file.write(string)
>
> def __getattribute__(self, name):
> value = object.__getattribute__(self, name)
> if name == 'softspace':
> if not self._sp_enabled:
> raise AttributeError
> self._file.write('[get softspace <- %d]\n' % value)
> return value
>
> def __setattr__(self, name, value):
> if name == 'softspace':
> if not self._sp_enabled:
> raise AttributeError
> self._file.write('[set softspace -> %d]\n' % value)
> object.__setattr__(self, name, value)
>
> softspace enabled:
>
> >>> sys.stdout = File(sys.stdout)
> [set softspace -> 0]
> [get softspace <- 0]
> [set softspace -> 0]
> >>> 42
> [get softspace <- 0]
> [set softspace -> 0]
> 42[get softspace <- 0]
> [set softspace -> 1]
> [get softspace <- 1]
> [set softspace -> 0]
>
> [get softspace <- 0]
> [set softspace -> 0]
>
> softspace disabled:
>
> >>> sys.stdout._sp_enabled = False
> >>> 42
> 42>>> 42
> 42>>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: Forcing prompt to be on newline when embedding Python with

2017-01-06 Thread H Krishnan
Thanks for your help.

>
> >
> > I am working on embedding Python in my application.
>
> You forgot to tell us the version of Python that you're embedding.
>
> I am using Python2.7.


> > I have redirected sys.stdin and sys.stdout to call methods from a Qt
> TextEdit
> > widget. Everything works fine except that the Python prompt does not
> always
> > come in a new line:
> >
> >>>> dir()
> > ['__builtins__', '__doc__', '__name__', '__package__']>>>
> >
> > Why doesn't the prompt appear in a new line as with the default stdout?
>
> Are you using code.InteractiveConsole / code.interact?
>
> I am using code.InteractiveConsole().interact().


> If not, in what mode do you compile, Py_file_input ("exec") or
> Py_single_input ("single")? The latter executes PRINT_EXPR:
>
> >>> dis.dis(compile('1', '', 'single'))
>   1   0 LOAD_CONST   0 (1)
>   3 PRINT_EXPR
>   4 LOAD_CONST   1 (None)
>   7 RETURN_VALUE
>
> PRINT_EXPR in turn calls sys.displayhook on the value it pops from the
> stack. The default hook writes the repr of the value and a newline to
> sys.stdout, and it also references the value as "_" in the builtins
> module (2.x __builtin__).
>

I tried replacing sys.displayhook with a function that does not print newline 
but the newline still got inserted. So, I am not sure where the newline is 
coming from. In any case, I could override sys.displayhook to add a newline at 
the end and that seems to resolve my problem.


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

Thanks,
Krishnan

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


Re: Reading csv file

2013-12-16 Thread Krishnan Shankar
Hi Igor

You can use the following way to do this using "with" operator.

def Read_CSV_File(filename):
  with open(filename, "r") as csvfile:
  csvreader = csv.DictReader(csvfile)
  line = 1
  for row in csvreader:
  if line < 6:
 reader.next()
 line++
 continue

 # process the CSV

Rest of the things are pretty much straightforward.

Regards,
Krishnan


On Tue, Dec 17, 2013 at 10:50 AM, Igor Korot  wrote:

> Hi, ALL,
> Is there a better way to do that:
>
> def Read_CSV_File(filename):
>   file = open(filename, "r")
>   reader = csv.DictReader(file)
>   line = 1
>   for row in reader:
>   if line < 6:
>  reader.next()
>  line++
> # process the CSV
>
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Basic Doubt

2013-08-10 Thread Krishnan Shankar
Hi Fellow Python Friends,

I am new to Python and recently subscribed to the mailing list.I have a
doubt regarding the basics of Python. Please help me in understanding the
below concept.

So doubt is on variables and their contained value.

Why does in the below example from Interpreter exploration value of c take
pre existing memory location.

>>> a=10
>>> id(a)
21665504
>>> b=a
>>> id(b)
21665504
>>> c=10
>>> id(c)
21665504

I am actually assigning new value to c. But from the value of id() all
three variables take same location. With variables a and b it is ok. But
why c taking the same location?

Regards,
Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Basic Doubt

2013-08-10 Thread Krishnan Shankar
Thanks Tim,

This takes me to one more question.

'is' operator is used to compare objects and it should not be used to
compare data.

So can it be compared with 'False'.

i.e. Is this code possible

if a is False:
print 'Yes'
if b is False:
print 'No'

Because i recommended this should not be done. But my colleagues say it is
correct.

Regards,
Krishnan


On Sat, Aug 10, 2013 at 10:10 PM, Tim Chase
wrote:

> On 2013-08-10 21:03, Krishnan Shankar wrote:
> > >>> a=10
> > >>> id(a)
> > 21665504
> > >>> b=a
> > >>> id(b)
> > 21665504
> > >>> c=10
> > >>> id(c)
> > 21665504
> >
> > I am actually assigning new value to c. But from the value of id()
> > all three variables take same location. With variables a and b it
> > is ok. But why c taking the same location?
>
> As an internal optimization, CPython caches small integer values
>
>   >>> a = 256
>   >>> b = 256
>   >>> a is b
>   True
>   >>> a = 257
>   >>> b = 257
>   >>> a is b
>   False
>
> Because it's an internal implementation detail, you shouldn't count
> on this behavior (Jython or Cython or IronPython may differ; or
> future versions of Python may cache a different range of numbers).
>
> Generally, if you are using the "is" operator to compare against
> anything other than None, you're doing it wrong. There are exceptions
> to this, but it takes knowing the particulars.
>
> -tkc
>
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Introduction to my fellow Python Friends

2013-08-11 Thread Krishnan Shankar
Hi Friends,

I would like to introduce myself.

I am Krishnan from Chennai, India. I am using python for 2 years for Test
Automation. I am fascinated by the language and its capabilities. I am
willing to move into Python development and I am doing the best i can to
learn the language completely and contribute to open source.

I figured out that the best way is to talk to the experts and so i
subscribed to this mailing list. It will be cool if anybody can help me out
by telling the etiquette of this mailing list, like

1. How to acknowledge a reply? Should i put a one to one mail or send it to
the mailing list itself?
2. How can i see or get a question asked by someone else? (So that i can
reply for that with my best possible knowledge. I currently get as Python
mail Digest)
3. How can i use this mailing list in the best possible way?

I hope to have a wonderful time with Python here. I hope i am not wasting
your time. Sorry for the inconvenience if i am.

Regards,
Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .split() Qeustion

2013-08-13 Thread Krishnan Shankar
Hi,

>How can I use the '.split()' method (am I right in calling it a method?)

The .split() is a method in Python which comes as in built method for
String objects in Python. Any string defined in python will have the
ability to call this function.

>>> var = 'Hello how r u?'
>>> dir(var)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__',
'__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__',
'__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
'__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith',
'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower',
'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',
'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split',
'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate',
'upper', 'zfill']
>>> var.split()
['Hello', 'how', 'r', 'u?']
>>>

>writing each comma between words in the pie list in the following code?
Also, is there >a way to use .split instead of typing the apostrophes?
Thank you.

>import random
>pie=['keylime', 'peach', 'apple', 'cherry', 'pecan']
>print(random.choice(pie))

If you are talking about having predefined list pie with limited elements
like above it is ok to code them straightaway with apostrophes and others
will know that it is a predefined list.

Suppose if the elements in list come as a line in a file or is a string, it
will be better to use split() method and form a list. I hope Gary has
provided the example for the same.

pie = 'keylime peach apple cherry pecan'.split()

I hope this clarifies your doubt.

Regards,
Krishnan



On Tue, Aug 13, 2013 at 9:51 PM,  wrote:

> How can I use the '.split()' method (am I right in calling it a method?)
> without instead of writing each comma between words in the pie list in the
> following code? Also, is there a way to use .split instead of typing the
> apostrophes? Thank you.
>
> import random
> pie=['keylime', 'peach', 'apple', 'cherry', 'pecan']
> print(random.choice(pie))
>
> Eric
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Verifying Variable value

2013-08-14 Thread Krishnan Shankar
Hi Chandan,

Python has built-in module called pdb which can be used for debugging.
Importing it in the right place will be like setting break point in code
and will change the execution to debugging mode. We can use different
debugging commands ((n)ext, (c)ontinue, (s)tep  etc) to evaluate through
the code. Below is the link to module,

http://docs.python.org/2/library/pdb.html

We can run this code in the following way "python -m pdb filename.py" to
run it in pdb debugging mode. Else import pdb and set the trace at right
place like below.

For example
=
def method()
  import pdb;pdb.set_trace()   <<<--  import and set_trace()
  a = 20
  b =30
  c =  a + b

method()

While running you will get pdb prompt to debug the code line by line. The
execution will be in user's hands.  Like below,

> c:\users\krishnan\desktop\test.py(3)method()
-> a = 20
(Pdb) n
> c:\users\krishnan\desktop\test.py(4)method()
-> b =30
(Pdb) n
> c:\users\krishnan\desktop\test.py(5)method()
-> c =  a + b
(Pdb) n
--Return--
> c:\users\krishnan\desktop\test.py(5)method()->None
-> c =  a + b
(Pdb) c

You can explore the module and find it useful for debugging. I hope this
helps

Regards,
Krishnan


On Wed, Aug 14, 2013 at 3:12 AM, chandan kumar 
wrote:
Hi ,

Is there a way to validate variable values while debugging any python
code.Run below example  in debugging mode and i would like to know the
value of c (I know print is an option) with any other option other than
printing.
In C# or some other tools we can verify each statement and values. Is there
way to check each statement in python code like in c#.

Ex:
def method()
  a = 20
  b =30
  c =  a + b


Best Regards,
Chanadn

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


Re: Verifying Variable value

2013-08-14 Thread Krishnan Shankar
You can even use logging module in python to validate the variable values.
You can import the module and use any of the following levels in your
program

import logging

 logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO,
logging.DEBUG

For more you can refer to,

http://docs.python.org/2/library/logging.html
http://stackoverflow.com/questions/1623039/python-debugging-tips




On Wed, Aug 14, 2013 at 3:12 AM, chandan kumar wrote:

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


List getting extended when assigned to itself

2013-08-24 Thread Krishnan Shankar
Hi Python Friends,

I came across an example which is as below,

>>> var = [1, 12, 123, 1234]
>>> var
[1, 12, 123, 1234]
>>> var[:0]
[]
>>> var[:0] = var
>>> var
[1, 12, 123, 1234, 1, 12, 123, 1234]
>>>

Here in var[:0] = var we are assigning an entire list to the beginning of
itself. So shouldn't it be something like,

[[1, 12, 123, 1234], 1, 12, 123, 1234]

It happens when we do the below,

>>> var = [1, 12, 123, 1234]
>>> var[0] = var
>>> var
[[...], 12, 123, 1234]
>>>

Literally var[0] = var and var[:0] = var almost meens the same. But why is
the difference in output? Can anyone explain what happens when
slicing assignment and direct assignment.

Regards,
Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'int' object is not callable

2013-08-26 Thread Krishnan Shankar
Hi,

The problem is in the second line.

a = time.daylight()

The daylight is not a method in time module. It is clear here,
http://docs.python.org/2/library/time.html

Since it is not a method we cannot call it. It is just a integer variable .
It returns zero if DST timezone is not defined and returns non zero if
defined.

>>> import time
>>> a = time.daylight()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not callable
>>> a = time.daylight
>>> a
0
>>> type(time.daylight)


Regards,
Krishnan


On Tue, Aug 27, 2013 at 8:15 AM,  wrote:

> dear friends when i try to execute following lines
>
> import time
> a = time.daylight()
> print(a)
>
>
> result is
> TypeError: 'int' object is not callable
>
>
> why is this error and how can i solve this problem?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Doubt on generators behavior

2013-10-13 Thread Krishnan Shankar
Hi Friends,

I am new to Generators and was learning the same by experimenting. I wrote
a small code which is as below.

>>> def test_gen(var):
... print "The number is", var
... if var % 2 == 0:
... yield var
... else:
... print "Number is odd"
...
>>>

But when i was executing i saw a behavior i could not understand. When i
gave an even number,
1. The generator object was created
2. When i gave next the argument was yielded.
3. In the subsequent next the Stop Iteration was raised.

>>> res = test_gen(78)
>>> res.next()
The number is 78
78
>>> res.next()
Traceback (most recent call last):
  File "", line 1, in 
StopIteration

But When i ran with an odd number the result of "Number is odd" is printed.
But it seems the generator runs again by itself to Stop Iteration.

>>> res2 = test_gen(77)
>>> res2.next()
The number is 77
Number is odd
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
>>>

How did this happen automatically? I am not able to get the execution of a
generator. Can someone please help me in understanding?
Regards,
Krishnan
-- 
https://mail.python.org/mailman/listinfo/python-list


Accessing the Taskbar icons

2013-11-07 Thread Krishnan Shankar
Hi All,

I am automating an application in windows using python.

After installation i need to check if the applications icon has appeared in
Taskbar or not. If yes i need to right click the application.

I had been using pywinauto for the same but could not get the job done till
now.

I did the following,

app=pywinauto.application.Application()
hand=pywinauto.findwindows.find_windows(class='Shell_TrayWnd', title=u'')

When i use the handler, get the window and do a right click i am able to
click only in the taskbar and not icons. That maybe because i did not
recognise the icon yet.

Can you guide me how to do the same using pywinauto or pywin32?

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


SWIG, C++, and Mac OS X

2006-07-05 Thread Siddartha Krishnan
Hi,

I'm new to using python and SWIG. I am running Mac OS X 10.4. I have  
a C++ class which I want to access from python, however I am unable  
to compile it as a shared module in Mac OS X.

I have tried using Distutils and have successfully created a C  
extension module, however I am unable to create a C++ extension  
module (I dont know how to pass the -c++ parameter to swig in the  
setup.py file.

I'd appreciate it If anyone could help me with creating a setup.py  
file for use with c++ or compiling a shared module on OS X.

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


urllib2 on Windows Vista

2006-07-08 Thread Sriram Krishnan
I'm running Python 2.4.3 on Windows Vista June CTP. I'm not able to
open any site using the urllib2 and related family of modules

Here's what I get

>>> import urllib2
>>> urllib2.urlopen("http://www.microsoft.com";)
Traceback (most recent call last):
  File "", line 1, in ?
  File "D:\python24\lib\urllib2.py", line 130, in urlopen
return _opener.open(url, data)
  File "D:\python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "D:\python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "D:\python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "D:\python24\lib\urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "D:\python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: 

Is this a known issue on Windows Vista?

Thanks,
Sriram

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


Re: urllib2 on Windows Vista

2006-07-09 Thread Sriram Krishnan

Rune Strand wrote:
> My wil guess is that it is a firewall problem. Perhaps you'll have to
> specify that python.exe is trusted.

Tried that - it didn't work. I also tried turning off the User Account
Control and ran as full administrator - that didn't work too.

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


Re: editor for Python on Linux

2006-02-19 Thread Sriram Krishnan
Mladen Adamovic wrote:
> Hi!
> 
> I wonder which editor or IDE you can recommend me for writing Python 
> programs. I tried with jEdit but it isn't perfect.
> 

Check out http://wiki.python.org/moin/PythonEditors. I personally use Emacs

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


Newbie Question:Please help

2008-09-08 Thread Karthik Krishnan
Hi,

I am a newbie to python and I hope this is not a stupid question. I am
trying to run a main method from a Python command line using the command
shell using the command.

python main_test.py

I get the following error.


File "", line 1
  python main_test.py

Syntax Error: invalid syntax

My main file main_test.py is given below.

#!/usr/bin/env python

""" Test method to run the main method.

"""

def main():
  print "Main method called.";


if __name__ = "__main__":
  main()
--
http://mail.python.org/mailman/listinfo/python-list

Python 2.6 and sys.exit()

2009-11-12 Thread H Krishnan
Hello,

I have the following in exit.py:
import sys
sys.exit(0)

I now try 'python -i exit.py':

In 2.5, the script exits as I would expect.

In 2.6, the following error is printed:

Traceback (most recent call last):
  File "exit.py", line 2, in 
sys.exit(0)
SystemExit: 0
>>>

I couldn't find anything related to this in "What's new in 2.6".

Is there any way I can get 2.6 to behave like 2.5?

Thank you for your help,

Regards,
H. Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


In Python and Windows environment how to supress certain key press and send some other key event for it

2017-04-02 Thread Krishnan Shankar
Hi All,

I was trying to build a VIM like shortcuts in windows. For example,

IF i press CAPSLOCK & h: It should "{Left}" move one to left. If CAPSLOCK &
b: It should "{Ctrl Down}{Left}{Ctrl Up}" move one word left etc.

I was successful in sending the key event. I used libraries like,

1. pynput
2. keyboard

for the same.

But i was unable to supress the Initial key event (ex: Caplock & h)

I tried using the keyboard to listen for key press events and supress them
as below.

>>>>>
import keyboard

def move_one_left():
"""
Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event
:return:
"""
keyboard.send(75)

def move_one_word_left():
"""
Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event
:return:
"""
keyboard.send('ctrl+left')

def main():
"""
This is the main loop which reads the key pressed.
According to the hotkey registered the function hooked is called.
The corresponding function will be the wrapped combination send back.
For example: CAPS + b is wrapped to Moving to left.
The main loop exits when Ctrl + c is done. So that is not registered.
:return:
"""
try:
# Start of the main loop
# Registering the hotkeys
# CAPS LOCK + H
keyboard.add_hotkey('caps lock+h', move_one_left, suppress=True)
# CAPS LOCK + B
keyboard.add_hotkey('caps lock+b', move_one_word_left,
suppress=True)

while True:
# Read the key pressed
print (keyboard.read_key())
except KeyboardInterrupt:
print("User has exited the program")

if __name__ == "__main__":
main()

<<<<<


This is working for sending the event for key press but the initial
keypress is also being send. The supress=True is not working.

Am I doing something wrong or is there any better way to supress the
initial key event and send another key event in place of that.


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


Load averages and Python threads on different Linux cloud provider setup

2011-05-31 Thread Mohanaraj Gopala Krishnan
Hello,

Apologies if this post is off topic.

We have a Python application that polls directories using threads and
inotify watchers. We have always run this application in a cloud
server provided by Voxel (http://www.voxel.net). We are currently
testing a different cloud server provider StormOnDemand
(http://stormondemand.com) and when we ran our application, our load
averages were a lot higher then they were when they were running on
the Voxel cloud server despite the specs being about the same (Refer
below for more details on setup). We have also ensured then when
testing the server was not handling any other loads.

I have written a simple test application (test_threads.py - attached,
or refer to http://pastebin.com/xGQU7JD0) that simulates the issues we
are seeing by starting up  threads that loops, sleeping for a user
defined time on each loop. It takes 2 parameters, the amount of
threads to start and the interval period.

When I run, "python test_threads.py 50 0.1" for about 10 minutes

Load average results:

StormOnDemand:
$ uptime
 18:46:22 up  7:29,  6 users,  load average: 4.43, 4.16, 2.93

voxel.net
$ uptime
 18:48:14 up 9 days, 15:09,  9 users,  load average: 0.51, 0.47, 0.43

The load average on the StormOnDemand server is a lot higher.

Python version:
StormOnDemand - 2.6.5
Voxel - 2.6.5

Server spec:
StormOnDemand - 8 x Intel(R) Xeon(R) CPU E5506 @ 2.13GHz; 16GB RAM;
230GB HDD (Storm Bare Metal servers)
Voxel - 7 x Intel(R) Xeon(R) CPU L5640 @ 2.27GHz; 14GB RAM; 200GB HDD
(VoxCloud servers)

OS:
StormOnDemand - Ubuntu 10.04 - 2.6.36-rc8101910 #1 SMP Tue Oct 19
19:18:34 UTC 2010 x86_64 GNU/Linux
Voxel - Ubuntu 10.04 -  2.6.32-31-server #61-Ubuntu SMP Fri Apr 8
19:44:42 UTC 2011 x86_64 GNU/Linux

Virtualisation method:
StormOnDemand - Not 100% sure, but I think they use Xen
Voxel - Not sure, but the image that we are using looks to us like a
stock standard Ubuntu 10.04 server

Any suggestion on why the load would be a lot higher or how I could
debug this further is greatly appreciated.


-- 
Mohan
#Simple script to test load when running python threads
# usage:
# python test_threads.py  
# e.g. :
# python test_threads.py 50 0.1
#

import sys
from threading import Lock, Thread
import logging
import time

logging.basicConfig()

log = logging.getLogger("test")
log.setLevel(logging.DEBUG) 

class MonitorDir(Thread):
def __init__(self, id, interval):
super(MonitorDir, self).__init__()
  	self.interval = interval 
self.id = id 
self._terminated = False

def finish(self):
if not self._terminated:
log.info('Terminating... %i'%self.id)
self._terminated = True

def run(self):
print 'Start threadi %i'%self.id

try:
while not self._terminated:
log.info('in id - %i \n'%self.id)
time.sleep(self.interval)
except:
log.exception('Unexpected error while monitoring')
finally:
log.info('Done monitoring')


if __name__ == '__main__':
mThreads = []
for i in range(int(sys.argv[1])):
print "create thread %i"%i
	mThread = MonitorDir(i, float(sys.argv[2]))
	mThreads.append(mThread)
	mThread.start()

while any(x.isAlive() for x in mThreads):
try:
	time.sleep(1)
except KeyboardInterrupt:
	log.debug('Exiting...')
	break
else:
   sys.exit(1) 

for mThread in mThreads:
mThread.finish()

for mThread in mThreads:
mThread.join()

sys.exit(0)
-- 
http://mail.python.org/mailman/listinfo/python-list