Running compiled Python files

2006-05-03 Thread Shankar
Hello,

I am trying to run compiled Python files (*.pyc and *.pyo) using Python C 
API.

I am using the method PyRun_FileFlags() for this purpose.

The code snippet is as follows:-

PyCompilerFlags myFlags;
myFlags.cf_flags=1; // I tried all values 0, 1 and 2
PyRun_FileFlags(script, file, Py_file_input, globals, locals, &myFlags);

But unfortunately I get the following exception:-
"DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line 
1, but no encoding declared; see http://www.python.org/peps/pep-0263.html 
for details"

When I run the .py file, then things work fine.
The .py file contains only one statement,
print "Hello World"

Which Python C API should I use to run compiled Python files(*.pyc and 
*.pyo) in the scenario where the source file (*.py) is not present.

Thanks in advance,
Regards,
skn 


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


Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?

2006-05-05 Thread Shankar
Hello,

I am trying to run compiled Python files (*.pyc and *.pyo) using Python C
API.

I am using the method PyRun_FileFlags() for this purpose.

The code snippet is as follows:-

PyCompilerFlags myFlags;
myFlags.cf_flags=1; // I tried all values 0, 1 and 2
PyRun_FileFlags(script, file, Py_file_input, globals, locals, &myFlags);

But unfortunately I get the following exception:-
"DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line
1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details"

When I run the .py file, then things work fine.
The .py file contains only one statement,
print "Hello World"

Which Python C API should I use to run compiled Python files(*.pyc and
*.pyo) in the scenario where the source file (*.py) is not present.

Thanks in advance,
Regards,
Shankar



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


Accessing std::wstring in Python using SWIG

2006-05-09 Thread Shankar
Hello,

I have a C++ dll with one class which has one public function.
This function returns an std::list as an argout.
I am using SWIG to generate Python extensions for this dll.

I have the following code in python to access the string from the list.

.
.
for item in myList:
  print str(item)
.
.

When I run this program I see that the address of the string is printed, but 
not the actual content.
Within Python code how can I dereference this wstring pointer to actually 
print the value and not the address.

Thanks in advance,
With best regards,
Shankar 


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


Python Contribution

2011-07-13 Thread Shankar Raman
 Hello everyone,
 My name is Shankarraman and I have been working with Python for past 5
months.I find it really interesting and cool and would like to know
different ways I can contribute to it. Though I went through the bug lists,
I was wondering if I could contribute to Python in other ways.

-- 
Namashivaya,
R.Shankarraman,
Computer Science and Engineering,
Amrita School of Engineering.
-- 
http://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


Query regarding PythonQt

2008-06-27 Thread Shankar Narayana
Hi,
 I am newbie to PythonQt. I wanted to access the Qt objects created in C++
using Python and update things. I had a look at this URL "
http://doc.trolltech.com/qq/qq23-pythonqt.html#decoratorsandcwrappers"; which
talks about using PythonQt for the same.
  I followed the instructions given in the example. I created my cpp file
and .py file and could make them working.
  But once after the first time after .pyc file is created, my program no
longer executes. It is giving me a segmentation fault. If I remove my .pyc
file and run the program, things work fine.

My cpp file
#include 
#include 
#include "PythonQt.h"
int main(int argc, char* argv[])
{
QApplication app(argc,argv);
QTextEdit *welcomemsg = new QTextEdit("Hi whatsup");
PythonQt::init();
PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
mainModule.addObject("welcomemsg",welcomemsg);  // Check with different
names
mainModule.evalFile("Pyscript.py");
mainModule.removeVariable("welcomemsg");
PythonQt::cleanup();
return app.exec();
}

My Python file  (Pyscript.py)

from PythonQt import *
#append the text to the existing text edit
welcomemsg.append("Hurray I did it")
welcomemsg.show()

Can somebody help me what makes this not to run once Python interpreter
works on the Python file and creates a .pyc file ?


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

Re: Query regarding PythonQt

2008-06-28 Thread Shankar Narayana
Hi,
  Can somebody please help me with the issue of ".pyc" creating problems
when we rerun the application, written using PythonQt ? The description of
the problem is given below.

Regards,
Shankar

On Fri, Jun 27, 2008 at 2:41 PM, Shankar Narayana <[EMAIL PROTECTED]>
wrote:

> Hi,
>  I am newbie to PythonQt. I wanted to access the Qt objects created in C++
> using Python and update things. I had a look at this URL "
> http://doc.trolltech.com/qq/qq23-pythonqt.html#decoratorsandcwrappers";
> which talks about using PythonQt for the same.
>   I followed the instructions given in the example. I created my cpp file
> and .py file and could make them working.
>   But once after the first time after .pyc file is created, my program no
> longer executes. It is giving me a segmentation fault. If I remove my .pyc
> file and run the program, things work fine.
>
> My cpp file
> #include 
> #include 
> #include "PythonQt.h"
> int main(int argc, char* argv[])
> {
> QApplication app(argc,argv);
> QTextEdit *welcomemsg = new QTextEdit("Hi whatsup");
> PythonQt::init();
> PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
> mainModule.addObject("welcomemsg",welcomemsg);  // Check with different
> names
> mainModule.evalFile("Pyscript.py");
> mainModule.removeVariable("welcomemsg");
> PythonQt::cleanup();
> return app.exec();
> }
>
> My Python file  (Pyscript.py)
>
> from PythonQt import *
> #append the text to the existing text edit
> welcomemsg.append("Hurray I did it")
> welcomemsg.show()
>
> Can somebody help me what makes this not to run once Python interpreter
> works on the Python file and creates a .pyc file ?
>
>
> Regards,
> Shankar
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Query regarding PythonQt

2008-06-30 Thread Shankar Narayana
Hi,
  After a big fight, I could get through the problem. I am posting it so
that others does not waste  time solving the issue.
I dont know why "evalfile" method is having problems with existing .pyc
files. But, we can solve it this way.
First create your .cpp and .py file in  directory. Then, do the
following
1. Create somename.qrc file
 
 
 Filename.py
 
  2. Navigate to the directory . Type the command: qmake
-project (It creates project (.pro) file)
3. Next command: qmake (It creates a make file).
4. Then update the makefile  INCPATH to add for Python and Python-Qt
-I/usr/include/python2.5 -I/home/workspace/PythonQt-1.0/src
5. Update the LIBS  -L/usr/lib/python2.5/config/libpython2.5.a
-L/home/workspace/PythonQt-1.0/lib -lpython2.5 -lPythonQt
WARNING: Always use ":" in your cpp file eval command. Then
only Qrc will be used to create the corresponding. pyc file. Otherwise, the
terminal will crash.
Now issue the command "make" and run your application. Things work fine now.

I am not very clear with QRC but its a very good solution.

Rgds,
Shankar


On Fri, Jun 27, 2008 at 2:41 PM, Shankar Narayana <[EMAIL PROTECTED]>
wrote:

> Hi,
>  I am newbie to PythonQt. I wanted to access the Qt objects created in C++
> using Python and update things. I had a look at this URL "
> http://doc.trolltech.com/qq/qq23-pythonqt.html#decoratorsandcwrappers";
> which talks about using PythonQt for the same.
>   I followed the instructions given in the example. I created my cpp file
> and .py file and could make them working.
>   But once after the first time after .pyc file is created, my program no
> longer executes. It is giving me a segmentation fault. If I remove my .pyc
> file and run the program, things work fine.
>
> My cpp file
> #include 
> #include 
> #include "PythonQt.h"
> int main(int argc, char* argv[])
> {
> QApplication app(argc,argv);
> QTextEdit *welcomemsg = new QTextEdit("Hi whatsup");
> PythonQt::init();
> PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule();
> mainModule.addObject("welcomemsg",welcomemsg);  // Check with different
> names
> mainModule.evalFile("Pyscript.py");
> mainModule.removeVariable("welcomemsg");
> PythonQt::cleanup();
> return app.exec();
> }
>
> My Python file  (Pyscript.py)
>
> from PythonQt import *
> #append the text to the existing text edit
> welcomemsg.append("Hurray I did it")
> welcomemsg.show()
>
> Can somebody help me what makes this not to run once Python interpreter
> works on the Python file and creates a .pyc file ?
>
>
> Regards,
> Shankar
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Testing for connection to a website

2008-07-17 Thread Venky Shankar
ping the universal DNS ? (4.2.2.2)

-Venky

On Wed, Jul 16, 2008 at 1:17 AM, Jordan <[EMAIL PROTECTED]> wrote:

> On Jul 15, 3:43 pm, Alexnb <[EMAIL PROTECTED]> wrote:
> > Okay, I already made this post, but it kinda got lost. So anyway I need
> to
> > figure out how to test if the user is able to connect to a specific
> website.
> > Last time I got pointed to the urllib2 page, but if I do urlopen() and
> and
> > am not connected, the program stops. So I don't know if that was what you
> > guys wanted me to do, but I don't think so, you guys are smarter than
> that.
> > So, how can I test for connection to a website.
> > --
> > View this message in context:
> http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p...
> > Sent from the Python - python-list mailing list archive at Nabble.com.
>
> Ping it? ~_^
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Testing for Internet Connection

2008-07-17 Thread Venky Shankar
may be try to open a connection to 4.2.2.2 at port 53 ?

-vks

On Wed, Jul 16, 2008 at 12:13 AM, norseman <[EMAIL PROTECTED]> wrote:

>
> Grant Edwards wrote:
>
>> On 2008-07-15, Alexnb <[EMAIL PROTECTED]> wrote:
>>
>>  What exactly do you think will work? I am not sure what you
>>> think I should do? If I use urlopen("http://www.google.com";)
>>> and I am not connected, I am not going to get an exception,
>>> the program will fail.
>>>
>>
>> Bullshit.  You get an exception.  Here's my program:
>>
>>   import urllib2
>>   try:
>>   con = urllib2.urlopen("http://www.google.com/";)
>>   data = con.read()
>>   print data
>>   except:
>>   print "failed"
>>
>> If I run it with no internet connection, I get this:
>>
>>   $ python testit.py
>>   failed
>>
>> If I bring up the internet connection, then I get a bunch of
>> HTML.
>>
> =
> Yep -me two
>
> Process:
> copy/paste into afile
> slide lines left to create proper indent values
> save
> python afile
>
> I get same as Grant
>
>
> If one does a copy/paste into interactive Python, it does fail.
> (Lots of indent error messages.  After all, it is Python :)
>
>
> Steve
> [EMAIL PROTECTED]
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
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


Re: Question

2008-07-19 Thread Venky K Shankar
On Saturday 19 July 2008 03:14:20 pm Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
> > Why is Perl so much better than python?
>
> Because you have the video:
>
> http://mail.python.org/pipermail/python-list/2004-March/253370.html

>> what about this ? i feel python's better :)
>> http://www.monstersandcritics.com/people/news/article_1339060.php
>
> --
> http://mail.python.org/mailman/listinfo/python-list


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

Re: How do you check if a program/process is running using python?

2008-07-19 Thread Venky K Shankar
On Sunday 20 July 2008 12:08:49 am Lamonte Harris wrote:
> How do you check if a program or process is running when using python? 
> What I want to do is have an infinite loop to check if a program is running
> or not and send data to my web server to check yes or no.  Is this
> possible? If so how?

you can execute OS system call.

here i execute ps -ef and grep the required process name (or you can grep by 
pid on that particular column using awk)

import os
os.system("ps -ef | grep -v grep | grep ")  

in my system it gives result 0 if the process is running

>>> a = os.system("ps -ef | grep -v grep | grep python")
root  8749  5331  0 Jul19 pts/100:00:00 python
>>> a
0

else gives non 0 :

>>> a = os.system("ps -ef | grep -v grep | grep python123")
>>> a
256

you can check this inside while True:

I am sure there should be a far better solution that this in python.

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


Frame widget (title and geometry)

2005-06-24 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

  I am still new to Python and Tkinter, so I apologize in advance if I do 
not word my question optimally.  I am trying to use a frame widget as the 
parent for other widgets.  There is a class with the header "class 
classtitle(Frame):" in a script called classtitle.py.  Having imported 
classtitle, I create a Frame widget within my gui using the command "w = 
Frame(self)."  Then, I grid this widget and issue the command "classinstance = 
classtitle.classtitle(w)."  When I attempt to execute this code, I receive an 
error claiming that w lacks geometry and title attributes that the code in 
classtitle.py attempts to access.  Does this mean that I cannot use a Frame 
widget as w in this situation?  Thanks for your help.

Shankar

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


Re: Frame widget (title and geometry)

2005-06-24 Thread Shankar Iyer ([EMAIL PROTECTED])
Here is an example of what I tried to do:

from Tkinter import *
import classtitle
import classtitle2

BLUE1 = '#7080B0'
RED1 = '#B08080'

class Master(Frame):

def createWidgets(self):

self.FrameOne = Frame(self)
self.FrameOne.grid(sticky = NW)
self.FrameOne["background"] = BLUE1
self.FrameOneClassInstance = classtitle.constructor(self.FrameOne)

self.FrameTwo = Frame(self)
self.FrameTwo.grid(sticky = SW)
self.FrameTwo["background"] = RED1
self.FrameTwoClassInstance = classtitle2.constructor(self.FrameTwo)

def __init__(self,master = None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()

app = Master()
app.mainloop()

The constructor methods in the two classes call, for example, 
self.FrameOne.geometry or self.FrameTwo.title and then I get errors which claim 
that these attributes do not exist.  I do think, however, that the Frame widget 
is what I want to use.  I want to partition my root window into several smaller 
sections.

Shankar


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


plot module

2005-07-12 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

I am looking for documentation on the plot module.  Does anyone know where I 
can find this information?  Thanks.

Shankar

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


loop problem

2005-07-13 Thread Shankar Iyer ([EMAIL PROTECTED])

Hi, First, I want to thank those who responded to my question about "the plot module" yesterday.  I realize now that the question could have been vague.  There is a plot module, simply called "plot," that I am using, and I guess it is not a very widely circulated plotting utility.    Anyway, I'm a little confused by the output that I get from the following code:
/***/
from Tkinter import *from tkSimpleDialog import *import Pmwimport HP34401Aimport plotimport time
class Application(Frame):
    def __init__(self,master=None):    Frame.__init__(self,master)    self.pack()    self.graph = plot.plot(self)    self.beginplotting()
    def beginplotting(self):    x = []    y = []    i = 0    fLastOutput = time.time()    while 1:    fTime = time.time()    if((fTime-fLastOutput) >= 2):    i += 1    x.append(fTime)    y.append(2*fTime)    self.graph.addSet(x,y)
    fLastOutput = fTime    if(i>=30):break
app = Application()app.mainloop()
/***/
This is supposed to plot a point every two seconds.  When it actually runs, it instead stores all the data points and then plots them after 30 data points have been taken.  I'm fairly certain that this is not due to the use of the plot class.  If I have the program instead write each time into a Tkinter Text widget, the same type of thing happens.  That is, the program stores all 30 times in memory and then dumps them into the Text widget at the end.  Since I have written the code so that it plots (or writes to the Text widget) every two seconds, I am confused as to why this is happening.
Shankar

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

Tkinter Button widget

2005-07-14 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

 I have another Tkinter-related question.  At the beginning of my program, 
a tkinter window is created with six buttons.  Each of these buttons is 
assigned a function that should be executed only when the button is pressed.  
However, it seems that these functions are all executed once when the button 
widgets are first created.  Why is this the case and how do I prevent this from 
happening?

Shankar

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


a question from a newcomer to this language

2005-06-10 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

I am a undergraduate physics student, and I have been asked to write some code 
in Python for my summer job.  Over the past few days, I have been learning 
Python and Tkinter, so naturally, I have several questions about the language.  
Here's one:

Is there any way to convert a string into an instruction that will be executed? 
 For example, suppose there's a string sString = "z = x*y".  Is there any way 
to have the instruction z = x*y be executed by performing some operation on 
sString?

Thanks in advance for your help.

Shankar  

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


Re: RE: a question from a newcomer to this language

2005-06-10 Thread Shankar Iyer ([EMAIL PROTECTED])

Thank you for your help.  I will post the problem in more detail if I find that 
I cannot avoid using exec.

Shankar  

- Original Message -
From: Michael Chermside <[EMAIL PROTECTED]>
Date: Friday, June 10, 2005 3:49 pm
Subject: RE: a question from a newcomer to this language

> Shankar writes:
> > Is there any way to convert a string into an instruction that 
> will be
> > executed?
> 
> Short answer:
>Yes. The exec statement does what you want:
> 
> >>> x = 3
> >>> y = 4
> >>> exec "z = x * y"
> >>> print z
> 12
> 
> HOWEVER... the long answer is that you almost certainly do NOT want
> to use exec. Nearly everything that can be done with exec can be
> done without it and the solution that does NOT use exec is faster,
> more understandable, and has better security features. Often the
> solution that does not use exec will be simpleer and more elegant
> as well.
> 
> If you look at a problem and are nearly certain that it needs to be
> solved using exec, try posting it here... the people on this newsgroup
> are very good at solving challenges like that. But try it yourself
> first... you may learn something.
> 
> -- Michael Chermside
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

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


bind in Tkinter

2005-06-10 Thread Shankar Iyer ([EMAIL PROTECTED])

I have been trying to learn how to associate keyboard events with actions taken 
by a Python program using Tkinter.  From what I've read online, it seems that 
this is done with the bind methods.  In one of my programs, I have included the 
following:

self.enternumber = Entry(self)
self.enternumber.bind("",self.quit)
self.enternumber.pack({"side":"top"})

It seems to me that, as a result of this code, if the enternumber Entry widget 
is selected and then the  key is pressed, then the program should quit. 
 Indeed, it seems that the program does attempt to quit, but instead an error 
message appears claiming that quit() takes 1 argument but 2 are given.  I get 
the same type of error if I replace self.quit with some function that I have 
written.  I am not sure how to fix this problem and hope that someone here can 
spot my error.  Thanks for your help.

Shankar


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


Re: bind in Tkinter

2005-06-10 Thread Shankar Iyer ([EMAIL PROTECTED])

I believe the quit function is built in.  Anyway, I get the same type of error 
if I substitute a function that I have defined.

Shankar

- Original Message -
From: VK <[EMAIL PROTECTED]>
Date: Friday, June 10, 2005 4:53 pm
Subject: Re: bind in Tkinter

> Shankar Iyer ([EMAIL PROTECTED]) wrote:
> > I have been trying to learn how to associate keyboard events with 
> actions taken by a Python program using Tkinter.  From what I've 
> read online, it seems that this is done with the bind methods.  In 
> one of my programs, I have included the following:
> > 
> > self.enternumber = Entry(self)
> > self.enternumber.bind("",self.quit)
> > self.enternumber.pack({"side":"top"})
> > 
> > It seems to me that, as a result of this code, if the enternumber 
> Entry widget is selected and then the  key is pressed, then 
> the program should quit.  Indeed, it seems that the program does 
> attempt to quit, but instead an error message appears claiming that 
> quit() takes 1 argument but 2 are given.  I get the same type of 
> error if I replace self.quit with some function that I have 
> written.  I am not sure how to fix this problem and hope that 
> someone here can spot my error.  Thanks for your help.
> > 
> > Shankar
> > 
> > 
> Have you defined quit function?
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

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


Re: bind in Tkinter

2005-06-10 Thread Shankar Iyer ([EMAIL PROTECTED])
Thanks!

Your message guided me to the solution to my problem.

Shankar

- Original Message -
From: Markus Weihs <[EMAIL PROTECTED]>
Date: Friday, June 10, 2005 5:01 pm
Subject: Re: bind in Tkinter

> Hi!
> 
> If you press a key, a key-event is passed to the function, here to
> self.quit. This is the misterious second argument, which can be 
> useful if you e.g. want to check which key was pressed. Here is 
> a snippet to show how you can do it:
> 
> 
> from Tkinter import *
> 
> def quit_program(event):
>print event.keysym   # which key was pressed?
>root.quit()
> 
> root = Tk()
> e = Entry()
> e.bind("", quit_program)
> e.pack()
> root.mainloop()
> 
> 
> Regards, mawe
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

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


dir() with string as argument

2005-06-16 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

Suppose I have a string, sModuleName, that contains the name of a module.  I 
now want to see what functions are in that module, but if I call 
dir(sModuleName), I instead get the list of operations that can be done on a 
string.  Is there any way to convert the string into a format that I could feed 
to dir to cause the desired effect?  I think I could modify the string a bit 
and then use the exec command, but I was advised against that on this board 
last week.

Shankar

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