I would like a script that does something like:
x = 1
x += 1
exit
when I just type these in sequentially to ipython.
If I try just putting these in script.py and doing %run script.py, it doesn't work (neither does %run -i):
In [1]: %run test.py
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/Users/david/nice_pngs/test.py in <module>()
1 x = 1
2 x += 1
----> 3 exit
NameError: name 'exit' is not defined
In [2]: %run -i test.py
In [3]:
Related
I wrote this command in editor qpython3 in my Android Handy.(Mi A3)
Why I get (name not define) this error?
MY CODE:
a = contactsGetIds()
print(a)
Error:
/data/user/0/org.qpython.qpy3/files/bin/qpython3-android5.sh /storage/emulated/0/qpython/scripts3/.last_tmp.py && exit
thon/scripts3/.last_tmp.py && exit <
Traceback (most recent call last):
File "/storage/emulated/0/qpython/scripts3/.last_tmp.py", line 1, in
a = contactsGetIds()
NameError: name 'contactsGetIds' is not defined
1|:/ $
I am trying to get workers to output some information from their ipython kernel and execute various commands in the ipython session. I tried the examples in the documentation and the ipyparallel example works, but not the second example (with ipython magics). I cannot get the workers to execute any commands. For example, I am stuck on the following issue:
from dask.distributed import Client
client = Client()
info = client.start_ipython_workers()
list_workers = info.keys()
%remote info[list_workers[0]]
The last line returns an error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-19-9118451af441> in <module>
----> 1 get_ipython().run_line_magic('remote', "info['tcp://127.0.0.1:50497'] worker.active")
~/miniconda/envs/dask/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2334 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2335 with self.builtin_trap:
-> 2336 result = fn(*args, **kwargs)
2337 return result
2338
~/miniconda/envs/dask/lib/python3.7/site-packages/distributed/_ipython_utils.py in remote_magic(line, cell)
115 info_name = split_line[0]
116 if info_name not in ip.user_ns:
--> 117 raise NameError(info_name)
118 connection_info = dict(ip.user_ns[info_name])
119
NameError: info['tcp://127.0.0.1:50497']
I would appreciate any examples of how to get any information from the ipython kernel running on workers.
Posting here just for keeping track, I raised an issue for this on GitHub: https://github.com/dask/distributed/issues/4522
TypeError Traceback (most recent call last)
<ipython-input-51-08821007cb29> in <module>
1 values= input(' Enter some comma separated numbers : ') # Your help here will be much appreciated
2 List= values.split(',')
----> 3 x= tuple(List)
4 print('List : ', List)
5 print('Tuple : ', x)
TypeError: 'tuple' object is not callable
The above is my entire code, and i can't figure out where is the error. Also I am using a jupyter note from anaconda and my python version is 3.7.4.
I use Anaconda and jupyter notebook.
I installed Quantlib in an environment.
I run the following piece of code and get an AttributeError
import QuantLib as ql
calculation_date = ql.date(9,1,2008)
ql.Settings.instance().evaluationDate = calculation_date
The following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-3ded7a4b7cb5> in <module>()
----> 1 calculation_date = ql.date(9,1,2004)
2 ql.Settings.instance().evaluationDate = calculation_date
AttributeError: module 'QuantLib' has no attribute 'date'
How can I fix this problem?
I think it requieres caps? You should use Date instead of date
import QuantLib as ql
calculation_date = ql.Date(9,1,2008)
ql.Settings.instance().evaluationDate = calculation_date
I've got an error when I'm using passthru() to call a python script (using subprocess and pipe) with PHP.
Here is the error:
Traceback (most recent call last):
File "…/Desktop/h.py", line 11, in stdout=subprocess.PIPE)
#set up the convert command and direct the output to a pipe
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 1079, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
The PHP passthru:
<?php
passthru("/usr/bin/python2.5 /Users/Nagar/Desktop/h.py $argument1 $argument2 1 2>&1");
?>
My Python line which cause the error:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE) #set up the convert command and direct the output to a pipe
How to use stdout=subprocess.PIPE properly in the subprocess?
Looking forward your answers.
It looks like your PATH doesn't have the directory including the "convert" command. Try replacing:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE)
with:
p1 = subprocess.Popen(['/full/path/to/convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE)
where "/full/path/to/convert" might be something like "/usr/bin/convert".
It's because it needs to be executed through a shell, so you need to set shell argument to True:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE, shell=True)convert command and direct the output to a pipe