I'm trying to make a roguelike with python 3 and tdl, but when I try to run
it there's a 'console not defined' error (see image below) I tried to do things like import console or import win32console as console. But it shows the same error
This is the code I'm using:
Well, console appears to be a part of the tdl package, so you should try replacing console.draw_char with tdl.console.draw_char or add from tdl import console as one of your import statments.
Related
I am trying to use a Jupyter notebook that was written by somebody else around 8 years ago. And the contents are written in Python2 and not Python3 that I am using. I am new to it and I can't figure out the reason for the syntax error.
The following are the contents of the first cells that is giving a syntax error.
`# Always run this first
# NOTE: Do not define new basic variables in this notebook;
# define them in Variables_Q.ipynb. Use this notebook
# to define new expressions built from those variables.
from __future__ import division # This needs to be here, even though it's in Variables_Q.ipynb
import sys
import os
sys.path.append(os.path.join(os.path.dirname('/home/khushal/Desktop/Python/Git Repositories/PostNewtonian/PNTerms'
)) # Look for modules in directory above this one
exec(open('../Utilities/ExecNotebook.ipy').read(),{})
from ExecNotebook.ipy import execnotebook
try: execnotebook(VariablesNotebook)
except: execnotebook('Variables_Q.ipynb')`
The error is
File "/tmp/ipykernel_31372/53020713.py", line 11
exec(open('../Utilities/ExecNotebook.ipy').read(),{})
^
SyntaxError: invalid syntax
I tried to use a 2to3 jupter notebook converter but it didn't change the jupyter notebook at all and it is giving the same result.
I'm trying to import a Python file containing a single function into my Julia notebook in VSCode.
The file is called helloPython.py and contains a single function called helloFromPython.
It contains the following code.
def helloFromPython():
print("Hello Julia, it's me Python!")
It is located in the same directory as my notebook file.
My first cell looks as follows.
import Pkg
Pkg.add("PyCall")
Pkg.build("PyCall")
using PyCall
Importing inbuilt Python functions works as expected, e.g.
math = pyimport("math")
math.sin(math.pi / 4)
Defining and calling Python code on the fly also works as expected, for example
begin
py"""
def f(x):
return x**3
"""
f = py"f"
end
f(2) # prints 8
However, importing my local Python file does not work. My cell looks as follows.
pushfirst!(PyVector(pyimport("sys")."path"), "")
x = pyimport("helloPython")
x.helloFromPython()
There is no error message. The cell executes successfully and that's it.
I've tried the same using the inbuild terminal in VSCode starting the Julia command prompt and it works as expected.
What am I doing wrong here?
Edit: #alex338207 had a good idea here, so I'm updating my question.
Writing to a file works. Here is a minimal working example. The file helloPython.py contains the following code.
def helloFromPython():
f = open("test.txt", "a")
f.write("Hello Julia!")
f.close()
Calling the above in VSCode as describe above, works as expected. A file is created with the provided content "Hello Julia!".
However, returning stuff doesn't work. Here is another example.
def helloFromPython():
return "Hello Julia!"
Calling the above yields to the output nothing.
I've updated my issue on Github.
I'm trying to import a dataset into R. When I try to run the code I used to do this previously, the read_csv function no longer works. I tried importing the data manually by using the "import data" dropdown button instead. When I click on this, I get the error message "there is no package called 'tibble'" and cannot import the dataset. Any idea why this might be happening?
I am inside a directory structure where I have:
--train.lua
--utils
--sample.lua
train.lua has got an import line saying require('sample'), however when running the code Torch7 complains with the message
"module 'sample' not found:No LuaRocks module found for sample
I have tried changing instead to require('utils.sample'), but it still crashes. How to overcome this error?
I do not have the problem you described. Could you post the code in the files?
My three files:
main.lua
require 'utils.sample'
help()
utils/sample.lua
function help()
print("help")
end
I using th main.lua to run the code
I'm calling a sikuli function, inside Sikuli IDE, but I get this error "NameError: global name 'openApp' is not defined"...
If I try to do openApp('calc') in a new Sikuli blank file, it works, but if I use in another .sikuli file like:
def sample():
import myLib
# my Lib is .py file that I've created and put it on sikuli-script.jar
var = somevalue
myLib.myFunction(something)
openApp('calc')
I get the error with "openApp" and other sikuli funcions like "Key" (ex: Key.ENTER) too...
Hope I had explained that well
By default, Sikuli will insert a from sikuli import * into all main files. This error tends to occur when you import sikuli modules. If you are importing modules, you will need to add the import manually. See the documentation for more advice.
If your tests are in the same folder basically you can do,
import testName
reload(testName)
from testName import *
This will import your test and execute it's content.
testName should be name of the file without .sikuli extension
I ran into a similar problem was solved by putting from sikuli import * at the first line of any file you are importing. I hope this helps!
I only mentioned this, because with the imported files, I had the greatest overall success with this one, and it became habit to make this the first line.