I get an Error 6 with Asciimatics and Python - python-2.7

I am learning how to use asciimatics with Python.
When I try to run the following code:
from asciimatics.screen import Screen
from time import sleep
def demo(screen):
screen.print_at('Hello world!', 0, 0)
screen.refresh()
sleep(10)
Screen.wrapper(demo)
I get this error:
Traceback (most recent call last):
File "C:\Users\Patrick\Pictures\Python\Westhope\2.0\test.py", line 20, in <module>
Screen.wrapper(demo)
File "C:\Python27\lib\asciimatics\screen.py", line 1336, in wrapper
unicode_aware=unicode_aware)
File "C:\Python27\lib\asciimatics\screen.py", line 1245, in open
None))
error: (6, 'CreateFile', 'The handle is invalid.')

The short answer is that you are not running in a proper console/terminal window and you need to run inside the standard Windows command prompt instead.
See https://asciimatics.readthedocs.io/en/latest/troubleshooting.html#i-can-t-run-it-inside-pycharm-or-other-ides for more details.

Related

simulation problem due to the library import

I found a problem in the python program.I don't know what I have to do.
Cordially.
import pyautogui
im1 = pyautogui.screenshot()
im2 = pyautogui.screenshot('my_screenshot.png')
Traceback (most recent call last):
File "C:/Users/LENOVO/Desktop/yyyu.py", line 1, in <module>
import pyautogui
File "C:\Python27\lib\site-packages\pyautogui\__init__.py", line 84, in <module>
import pyscreeze
SyntaxError: 'return' with argument inside generator (__init__.py, line 168)
You probably get this error because you use python 2, try to use python 3

Syntax error while using python trace

I'm running a script of which I need to see which statements of whichever files it touches. So, I'm using Python's trace.
This command runs perfectly on the linux terminal: /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy
In another cluster_ha_original.py script I've this code:
import trace
cmd_to_run = '/x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy'
tracer = trace.Trace(count=False, trace=True)
tracer.run(cmd_to_run)
r = tracer.results()
r.write_results(summary=True)
The above cluster_ha_original.py file should have given me the complete trace which includes the files, functions and statements which cluster_ha.thpy internally calls but I'm getting a syntax error:
[nikhilh#cycl02 test]$ python3 cluster_ha_original.py
--- modulename: trace, funcname: _unsettrace
trace.py(78): sys.settrace(None)
Traceback (most recent call last):
File "cluster_ha_original.py", line 6, in <module>
tracer.run(cmd_to_run)
File "/usr/software/lib/python3.2/trace.py", line 501, in run
self.runctx(cmd, dict, dict)
File "/usr/software/lib/python3.2/trace.py", line 509, in runctx
exec(cmd, globals, locals)
File "<string>", line 1
/x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy
^
SyntaxError: invalid syntax
Any ideas?

How to resolve "_tkinter.TclError: unknown option"?

I am learning python tkinter but I have an error whenever I tried to compile it:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/
widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/jason/.spyder2/.temp.py", line 14, in <module>
menu.config(menu=menu)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1274,
inconfigure
return self._configure('configure', cnf, kw)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1265,
in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-menu").
My code is:
from tkinter import *
def hello():
print "hello"
root = Tk()
menu = Menu(root)
menu.config(menu=menu)
menu.add_command(label ="new",command = hello)
root.mainloop()
You have an issue with your code a little bit. Instead of menu.config, use root.config, you will not get any such errors.
For more information and detailed tutorial, kindly visit Tkinter Menu Widget.

os.system in a loop

For each item in a list, I am modifying a file and then I want to run the python script, "ncall.py", which imports the modified file called, "new_basketparams.txt". I also want to make sure ncall.py completes its process before recalling it, but that is perhaps another topic. I am working on an ubuntu linux machine with python 2.7.
Here's the issue: My code seems to call ncall.py infinite times, stuck inside of the loop. I cannot even use a keyboard shortcut to kill the process and must close the window to kill the process. Here is my code and if anyone can help explain a solution, or guide me, that would be greatly appreciated:
import os
import re
datelist=['2014-05-16','2014-05-15','2014-05-14','2014-05-13','2014-05-12']
for date in datelist:
f=open('basketparams.txt')
g=open('new_basketparams.txt','w')
for line in f:
if "Start" in line:
line=line.split(";")
line[2]=re.sub('\d\d\d\d-\d\d-\d\d',date,line[2])
line=';'.join(line)
elif "End" in line:
line=line.split(";")
line[2]=re.sub('\d\d\d\d-\d\d-\d\d',date,line[2])
line=';'.join(line)
else:
pass
g.write(line)
os.system("python ncall.py")
Here are some diagnostics. The import MySQL error is strange because ncall works when called by itself from the terminal
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "ncall.py", line 1, in <module>
import MySQLdb
ImportError: No module named MySQLdb
[]
calling ncall.py no. 1 2014-05-21 07:30:46.400011
new_basketparams.txt
Traceback (most recent call last):
File "ncall.py", line 15, in <module>
Price_Min=display.input[2]
IndexError: list index out of range
[]
calling ncall.py no. 1 2014-05-21 07:30:46.352573
new_basketparams.txt
Traceback (most recent call last):
File "ncall.py", line 15, in <module>
Price_Min=display.input[2]
IndexError: list index out of range
[]
calling ncall.py no. 1 2014-05-21 07:30:46.305043
new_basketparams.txt
Traceback (most recent call last):
File "ncall.py", line 15, in <module>
Price_Min=display.input[2]
IndexError: list index out of range
Now I am including a portion of code from ncall.py as well as display.py:
#ncall.py
import MySQLdb
import csv
import display
import time
from display import fileinput
from datetime import datetime, date, time, timedelta
import datelist
now0=datetime.now()
print fileinput
Start_Datetime='%s 14:00:00'%(datelist.date)
End_Datetime='%s 14:59:59'%(datelist.date)
Price_Min=display.input[2]
Price_Max=display.input[3]
Under=display.input[4]
#display.py
fileinput='new_basketparams.txt'
f=open(fileinput)
input=[]
for line in f:
print 'reading line in fileinput in display.py\'s loop: ', line
try:
line=line.split(';')
parameter=line[0]
Input=line[2]
x=Input.split('\r')
input.append(x[0])
except :
continue

Cannot execute runserver in Django: "TypeError: putenv() argument 2 must be string, not None"

I made and successfully ran Django project in Windows, but after copying it to Linux and executing command "python manage.py runserver" following error occured:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
os.environ.setdefault("DJANGO_SETTINGS_MODULE")
File "/home/blizzard/webapps/django_1_3/moz455/env0/lib/python2.6/UserDict.py", line 63, in setdefault
self[key] = failobj
File "/home/blizzard/webapps/django_1_3/moz455/env0/lib/python2.6/os.py", line 472, in __setitem__
putenv(key, item)
TypeError: putenv() argument 2 must be string, not None
Right values for key and item are "DJANGO_SETTINGS_MODULE" and "settings".
How to avoid this error?
Answer is so simple that this question should not be asked :) But maybe it save somebody several minutes.
For Linux correct command is
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'my_project_name.settings')