myProj= Proj('+proj=utm +zone=23 +south +units=m +ellps=WGS84', preserve_units=False)
NameError Traceback (most recent call last)
in
----> 1 myProj= Proj('+proj=utm +zone=23 +south +units=m +ellps=WGS84', preserve_units=False)
NameError: name 'Proj' is not defined
Related
This works:
ss = 'insert into images (file_path) values(?);'
dddd = (('dd1',), ('dd2',))
conn.executemany(ss, dddd)
However this does not:
s = 'insert into images (file_path) values (:v)'
ddddd = ({':v': 'dd11'}, {':v': 'dd22'})
conn.executemany(s, ddddd)
Traceback (most recent call last):
File "/Users/Wes/.virtualenvs/ppyy/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-31-a999de59f73b>", line 1, in <module>
conn.executemany(s, ddddd)
ProgrammingError: You did not supply a value for binding 1.
I am wondering if it is possible to use named parameters with executemany and, if so, how.
The documentation at section 11.13.3 talks generally about parameters but doesn't discuss the two styles of parameters that are described for other flavors of .executexxx().
I have checked out Python sqlite3 execute with both named and qmark parameters which does not pertain to executemany.
The source shows that execute() simply constructs a one-element list and calls executemany(), so the problem is not with executemany() itself; the same call fails with execute():
>>> conn.execute('SELECT :v', {':v': 42})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.ProgrammingError: You did not supply a value for binding 1.
As shown in the Python documentation, named parameters do not include the colon:
# And this is the named style:
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
So you have to use ddddd = ({'v': 'dd11'}, {'v': 'dd22'}).
The : isn't part of the parameter name.
>>> s = 'insert into images (file_path) values (:v)'
>>> ddddd = ({'v': 'dd11'}, {'v': 'dd22'})
>>> conn.executemany(s, ddddd)
<sqlite3.Cursor object at 0x0000000002C0E500>
>>> conn.execute('select * from images').fetchall()
[(u'dd11',), (u'dd22',)]
xn=input()
c=input()
xn1 = .5(xn+(c/xn))
print(str(xn1))
I can't seem to get this code to run. I get the following error message:
Traceback (most recent call last):
File "eq.py", line 3, in <module>
xn1 = .5(xn+(c/xn))
TypeError: 'float' object is not callable
I've looked up a number of other assignment statements in Python, but I can't seem to figure out what's wrong with this one. I also tried casting all the variables as floats.
You're trying to invoke .5 as if it were a function. Change the line:
xn1 = .5*(xn+(c/xn))
Example here: https://repl.it/F55K
I am scripting on a pfSense router box that is running python 2.7 and the standard library, as a result I don't have the modules pytz or dateutil to work with, and the strptime module doesn't support %z.
I need to convert date/times coming from another server (not local time) to a unix time stamp.
Is there a way I can insert the desired tz offset into a naive structured time and then convert it to GMT?
For Example consider the time 2016/08/14 02:15:10 [-0600/1] MDT coming from a remote server. My TZ is EDT -0400.
If the value was from my time zone, I could easily do something like this:
>>> t=datetime.datetime(2016,8,14,2,15,10).timetuple()
>>> print(t)
time.struct_time(tm_year=2016, tm_mon=8, tm_mday=14, tm_hour=2, tm_min=15, tm_sec=10, tm_wday=6, tm_yday=227, tm_isdst=-1)
>>> ts=time.mktime(t)
>>> print(ts)
1471155310.0
I need some way to do the conversion that allows me to pass a time zone offest (I need something like: time.mktime(t,offset=-21600) but of course it doesn't exist)
I have hard coded everything because I can easily get values, it's the time manipulation logic I need help with.
I also tried the following approach:
In strptime %z does not work.
>>> time.strptime("20160814 021510 -0600","%Y%m%d %H%M%S %z")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/_strptime.py", line 478, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/local/lib/python2.7/_strptime.py", line 324, in _strptime
(bad_directive, format))
ValueError: 'z' is a bad directive in format '%Y%m%d %H%M%S %z'
Unless it is my time zone even %Z does not work.
>>> time.strptime("20160814 021510 MDT","%Y%m%d %H%M%S %Z")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/_strptime.py", line 478, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/local/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '20160814 021510 MDT' does not match format '%Y%m%d %H%M%S %Z'
but if on my time zone strptime DOES work:
>>> time.strptime("20160814 021510 EDT","%Y%m%d %H%M%S %Z")
time.struct_time(tm_year=2016, tm_mon=8, tm_mday=14, tm_hour=2, tm_min=15, tm_sec=10, tm_wday=6, tm_yday=227, tm_isdst=1)
Using %z for numeric timezone is only supported from python 3.x here is a fix for python 2.7
Instead of using:
datetime.strptime(t,'%Y-%m-%dT%H:%M %z')
use the timedelta to account for the timezone, like this:
from datetime import datetime,timedelta
def dt_parse(t):
ret = datetime.strptime(t[0:16],'%Y-%m-%dT%H:%M')
if t[18]=='+':
ret+=timedelta(hours=int(t[19:22]),minutes=int(t[23:]))
elif t[18]=='-':
ret-=timedelta(hours=int(t[19:22]),minutes=int(t[23:]))
return ret
In Python I am running code to define a function. the first part appears to run ok but the second part throws a 'name not defined' error.
Here is the code;` #This this part runs fine.
def modelfit(alg, dtrain, predictors, performCV=True, printFeatureImportance=True, cv_folds=5):
#Fit the algorithm on the data
alg.fit(dtrain[predictors], dtrain['Target'])
# the part below this is where the error gets thrown
# Predict training set:
dtrain_predictions = alg.predict(dtrain[predictors])
dtrain_predprob = alg.predict_proba(dtrain[predictors])[:,1]
Here is the complete error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-22-edfedf10fb86> in <module>()
1 #Predict training set:
----> 2 dtrain_predictions = alg.predict(dtrain[predictors])
3 dtrain_predprob = alg.predict_proba(dtrain[predictors])[:,1]
NameError: name 'alg' is not defined
What am I doing wrong?
It is because the indentation of this function definition is not aligned. The "alg" is a variable defined by the function "modelfit", and indented out of alignment is considered a new variable outside the function.What you shoule do is just to adjust the indentation.
I am fairly new to Python, and am trying to learn the numerical methods concepts before understanding the program.
There is a .py file written for a function called phugoid.py, but I cannot seem to get the graph to show on ipython editor Sagemath. (Sagemath has matplotlib).
In [9]: %run phugoid.py
%matplotlib inline
In [1]: plot_flight_path(64, 16, 0)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-e57d3fb06a4a> in <module>()
1 #zt = 64, z = 16, theta = 0
----> 2 plot_flight_path(64, 16, 0)
NameError: name 'plot_flight_path' is not defined
Here is the github file of my project (it's only two files, the function and the notebook).
Sagemath Project Link
Github Project Link
Please explain what I am doing wrong for a 5 year old.... thanks.