[issue44549] BZip 1.0.6 Critical Vulnerability

2021-07-02 Thread siddhartha shankar mahato


New submission from siddhartha shankar mahato :

Python (3.9.5 and 3.9.6 are using Bzip2 1.0.6 which has a known critical 
vulnerability. 
CVE-2019-12900 (BDSA-2019-1844)
9.8 Critical NVD CVE-2016-3189 (BDSA-2019-2036).

Please upgrade the same to a stable version.

--
components: Windows
messages: 396853
nosy: paul.moore, s.s.mahato, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: BZip 1.0.6 Critical Vulnerability
type: crash
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue44549>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-08 Thread SHANKAR JHA


Change by SHANKAR JHA :


--
keywords: +patch
pull_requests: +18213
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18851

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-08 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

I have added the pull request: https://github.com/python/cpython/pull/18851. 
Please check it out and let me know if I need to change anything.

Thank you everyone for your guidance.

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39702] PEP 614: Relaxing Grammar Restrictions On Decorators

2020-03-08 Thread SHANKAR JHA


Change by SHANKAR JHA :


--
nosy: +shankarj67
nosy_count: 2.0 -> 3.0
pull_requests: +18208
pull_request: https://github.com/python/cpython/pull/18851

___
Python tracker 
<https://bugs.python.org/issue39702>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-07 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

I have created my draft with an example but I am confused about where exactly 
do I have to add the code and push it.

I have cloned these two repositories in my system and setup everything:
https://github.com/python/cpython
https://github.com/python/devguide

1. Please tell me where I should be adding my code. Do I have to add code here 
https://github.com/python/cpython/blob/master/Doc/reference/expressions.rst and 
push it?

2. I am working on the master branch only. Is there any specific branch I have 
to select?

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-06 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

I got it that I have to fill the "Assignment expression" section in the code. I 
am working on it and send you the for review once I am done.

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-06 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

I am also checking your commit for this: 
(https://github.com/python/cpython/commit/8bae21962bab2fac7630982abd73676b89930902)
 and see that you are changing the "expression: to "assignment_expression". 

Do I have to fill what assignment expression does with some examples?

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-06 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

Thank you for helping me out brandtbucher.

As per my understanding, I am looking into the code 
(https://github.com/python/cpython/blob/master/Doc/reference/expressions.rst) 
and finding where the code doesn't follow the pattern described in 
(https://www.python.org/dev/peps/pep-0572/.)

Please let me know if I am correct so that I will quickly go through everything 
and send you a pull request as soon as possible.

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-05 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

This is my first contribution to Python. This is why I am looking for some 
guidance, just point me to some resource, and then I will look into it 
thoroughly.

I am reading this https://www.python.org/dev/peps/pep-0572/ for better 
understanding.

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-05 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

Thank you for that!!!

Can you please provide some pointers to what exactly I have to do?

--

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39868] Stale Python Language Reference docs (no walrus).

2020-03-05 Thread SHANKAR JHA


SHANKAR JHA  added the comment:

Can I take this issue?

--
nosy: +shankarj67

___
Python tracker 
<https://bugs.python.org/issue39868>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36628] Enhancement: i-Strings

2019-04-15 Thread Aditya Shankar


Change by Aditya Shankar :


--
resolution: postponed -> duplicate

___
Python tracker 
<https://bugs.python.org/issue36628>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36628] Enhancement: i-Strings

2019-04-14 Thread Aditya Shankar


New submission from Aditya Shankar :

Problem: multiline strings are a pain to represent (other than of-course in 
docstrings), representing a multiline string inside a function looks something 
like this -

def foo():
# some code
...
...
# some code
text = """abc meta alpha chronos
dudes uptomes this text
is nonsense"""
return somethingwith(text)

or

def foo():
# some code
...
...
# some code
text = "\n".join(["abc meta alpha chronos",
  "dudes uptomes this text",
  "is nonsense"])
return somethingwith(text)

an enhancement would be - 

def foo():
# some code
...
...
# some code
text = i"""
abc meta alpha chronos
dudes uptomes this text
is nonsense
"""
return somethingwith(text)
i.e. all initial spaces are not considered as a part of the string in each ine

for example while throwing an exception -
def foo(bad_param):
...
try:
some_function_on(bad_param)
except someException:
throw(fi"""
you cant do that because, and I'm gonna explain
this in a paragraph of text with this {variable}
because it explains things more clearly, also
here is the {bad_param}
""")
...
which is far neater than -

def foo(bad_param):
...
try:
some_function_on(bad_param)
except someException:
throw(f"""you cant do that because, and I'm gonna explain
this in a paragraph of text with this {variable}
because it explains things more clearly, also
here is the {bad_param}""")
...

pros:
    - represented code is closer to output text
- implementation should not be too hard

--
components: Interpreter Core
messages: 340208
nosy: Aditya Shankar
priority: normal
severity: normal
status: open
title: Enhancement: i-Strings
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue36628>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36200] display index on IndexError

2019-03-05 Thread Aditya Shankar


Aditya Shankar  added the comment:

closed as this is a duplicate for https://bugs.python.org/issue18162

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue36200>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36200] display index on IndexError

2019-03-05 Thread Aditya Shankar


New submission from Aditya Shankar :

considering a list of 5 elements, if the 6th element is asked, the Interpreter 
would raise IndexError: list index out of range,
I think It'd be better if it actually said what the invalid index is

Improvement benefits:
*quicker debugging of faulty python code
*person debugging does not need to edit and restart the program to fix issue, 
sometimes at least

--

___
Python tracker 
<https://bugs.python.org/issue36200>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36200] display index on IndexError

2019-03-05 Thread Aditya Shankar


Change by Aditya Shankar :


--
components: +Interpreter Core
title: display index on Index -> display index on IndexError
type:  -> enhancement
versions: +Python 3.8

___
Python tracker 
<https://bugs.python.org/issue36200>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36200] display index on Index

2019-03-05 Thread Aditya Shankar


Change by Aditya Shankar :


--
nosy: Aditya Shankar
priority: normal
severity: normal
status: open
title: display index on Index

___
Python tracker 
<https://bugs.python.org/issue36200>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34773] sqlite3 module inconsistently returning only some rows from a table

2018-09-22 Thread Shankar


New submission from Shankar :

I am running a Python based system on an Android phone. The database is in 
Sqlite3.  It has been running well for approximately five years now, with 
various upgraded phones, changes to the system, etc.

However, in the last week or so, there has been a problem in the system that is 
very peculiar.  One of the tables on the system is called "Invoices" and it 
currently has approximately 21,500 records in it.  However, reading the 
database from Python on the phone, using the sqlite3 module, will suddenly 
return only around 2,400 records.  If I copy the database over to a PC and open 
it in Python via Linux, the same thing will happen.  If I then open it with the 
command line `sqlite3` tool, the table will read correctly.  After that, it 
will start working correctly in Python as well.  If I copy the same database 
back to the phone, it will work correctly there as well - for approximately 
three or four hours (i.e., given the usual frequency of my program, about 90 - 
120 reads / writes).  Then the problem will return.

I have changed phones in case this was a problem in the phone's memory, but 
that didn't help.  I have run `vacuum` on the sqlite3 database in question as 
well, to no avail.  There do not appear to be any other obvious errors in the 
database. 

What could be the reason for this behaviour?  

Below I've posted some of the code that I use to read the database.  Have cut 
out some extraneous stuff so you may see variables that are not defined etc. 
But I'm fairly sure it's not the code, as this same code has been running for 
years with no trouble.


def sqlite_exec(sqlcommand, dbname, inserttable = "", insertstuff = None, 
returndict = 0, override_stop = False, returncheck = False, nojournal = False, 
onlyjournal = False):
#...
if sqlcommand == "insert":
# Substitute single quotes with double quotes in input text to 
avoid sqlite syntax errors
actual_command = "INSERT INTO {0} ({1}) VALUES 
({2});".format(inserttable, ", ".join(insertstuff.keys()), ", ".join(["'" + 
re.sub("'",'"',valuetext) + "'" for valuetext in insertstuff.values()]))
else:
actual_command = sqlcommand
conn = sqlite3.connect(dbname,timeout = 40.0,isolation_level=None, 
detect_types=sqlite3.PARSE_DECLTYPES)
if returndict:
# Using the sqlite module documentation example; this happens to be 
better suited for our purposes than the sqlite.Row object
def dict_factory(cursor, row):
d = dict((col[0],row[idx]) for idx,col in 
enumerate(cursor.description))
return d
conn.row_factory = dict_factory
sqliteobj = conn.cursor()
# ...
if not onlyjournal:
try:
sqliteobj.execute(actual_command)
# except...
return sqliteobj

--
components: Extension Modules
messages: 326132
nosy: shankargopal
priority: normal
severity: normal
status: open
title: sqlite3 module inconsistently returning only some rows from a table
type: behavior
versions: Python 2.7

___
Python tracker 
<https://bugs.python.org/issue34773>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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


[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux

2014-04-26 Thread Shankar Unni

Shankar Unni added the comment:

 If you want to modify time.sleep(), you must be careful of the portability: 
 Windows, Linux, but also Mac OS X, FreeBSD, Solaris, etc.

Oh, I totally agree. What I'm trying to do is to define another autoconf flag 
(HAVE_CLOCK_NANOSLEEP), that does a feature test and enable that flag, and just 
use that if available.

Now that's a good point that if we have clock_nanosleep() on another platform 
(non-Linux) and it does the wrong thing, then I might have to add further 
discrimination.

For now, one sticking point that I've stumbled across is that clock_nanosleep() 
requires -lrt. Complicates the autoconf check a bit.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21302
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux

2014-04-18 Thread Shankar Unni

New submission from Shankar Unni:

I know that an earlier request to use nanosleep() has been rejected as 
wontfix, but I'm filing this one for a different reason.

Today, timemodule.c:floatsleep() calls select() on platforms that support it. 
On Linux, select() with a timeout has an unfortunate property that it is very 
sensitive to clock jumps, because it computes a sleep end time based on the 
current kernel timestamp.

If the system clock is yanked back (by ntpd, or other processes), then the 
process can end up sleeping for a very long time. (E.g. if the clock is yanked 
back by half an hour while we are in the middle of, say, a sleep(10), then the 
process will sleep until original_kernel_clock+10, which will turn into a 
half-hour sleep.

Yes, systems shouldn't jerk their clocks around, but we can't often control 
this sort of thing on end-user environments.

Using clock_nanosleep(CLOCK_MONOTONIC, 0, timespec, NULL) makes the sleep a 
much more reliable thing, and mostly insensitive to such jumps. (It'll still be 
affected by any adjtime(), but that's OK in this case).

--
components: Library (Lib)
messages: 216799
nosy: shankarunni
priority: normal
severity: normal
status: open
title: time.sleep (floatsleep()) should use clock_nanosleep() on Linux
type: behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21302
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux

2014-04-18 Thread Shankar Unni

Shankar Unni added the comment:

I'm working on a patch, but I noticed a similar issue in Condition.wait(), 
which also keeps re-evaluating the remaining sleep time based on the current 
kernel clock, with similar effects.

I'll try to address both issues, or we could open a separate bug for the 
latter..

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21302
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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 ikoro...@gmail.com 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


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


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 stdin, line 1, in module
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 stdin, line 1, in module
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


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 stdin, line 1, in module
TypeError: 'int' object is not callable
 a = time.daylight
 a
0
 type(time.daylight)
type 'int'

Regards,
Krishnan


On Tue, Aug 27, 2013 at 8:15 AM, autobotprime...@gmail.com 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


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: 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 chandan_...@yahoo.co.in
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 chandan_...@yahoo.co.inwrote:

 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: .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, eschneide...@comcast.net 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


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


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
python.l...@tim.thechases.comwrote:

 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


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: 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 proc_name)  

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


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

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 somedir directory. Then, do the
following
1. Create somename.qrc file
 !DOCTYPE RCCRCC version=1.0
 qresource
 fileFilename.py/file
 /qresource
 /RCC 2. Navigate to the directory somedir. 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 :pythonfilename 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 QApplication
 #include QTextEdit
 #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 QApplication
 #include QTextEdit
 #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

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 QApplication
#include QTextEdit
#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

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::liststd::wstring 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


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


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


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


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 insteadwrite 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

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


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


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


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


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(Return,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 Return 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