这是我的代码
def fahrenheit(T):
return ((float(9)/5)*T + 32)
temp = [0, 22.5, 40,100]
F_temps = map(fahrenheit, temp)
Run Code Online (Sandbox Code Playgroud)
这是mapobject所以我试过这样的东西
for i in F_temps:
print(F_temps)
<map object at 0x7f9aa050ff28>
<map object at 0x7f9aa050ff28>
<map object at 0x7f9aa050ff28>
<map object at 0x7f9aa050ff28>
Run Code Online (Sandbox Code Playgroud)
我不确定,但我认为我的解决方案可以用Python 2.7,如何用3.5改变它?
我在 Ubuntu 16.04 上,我已经用 pip 安装了 Airflow。下一步
airflow initdb
[2017-07-29 12:20:23,483] {__init__.py:57} INFO - Using executor SequentialExecutor
DB: sqlite:////home/milenko/airflow/airflow.db
[2017-07-29 12:20:23,813] {db.py:287} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
Run Code Online (Sandbox Code Playgroud)
这很好用。但是当我尝试启动网络服务器时
airflow webserver -p 8080
[2017-07-29 12:20:45,913] [4585] {models.py:167} INFO - Filling up the DagBag from /home/milenko/airflow/dags
Running the Gunicorn Server with:
Workers: 4 sync
Host: 0.0.0.0:8080
Timeout: 120
Logfiles: - -
=================================================================
[2017-07-29 12:20:46,950] {__init__.py:57} INFO - Using executor SequentialExecutor
[2017-07-29 12:20:47 +0200] [4590] [INFO] Starting gunicorn 19.3.0 …Run Code Online (Sandbox Code Playgroud) 我导入的Python模块
import Queue
from threading import Thread
import time
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时
File "b1.py", line 3, in <module>
import Queue
ModuleNotFoundError: No module named 'Queue'
Run Code Online (Sandbox Code Playgroud)
我在SO上看过类似的帖子,但对我来说没有用
/usr/bin/python3 --version
Python 3.5.2
milenko@milenko-System-Product-Name:~$ python --version
Python 3.6.0 :: Anaconda custom (64-bit)
Run Code Online (Sandbox Code Playgroud)
如果我换到
from multiprocessing import Queue
Run Code Online (Sandbox Code Playgroud)
没有进口问题.但比我有这个
AttributeError: 'Queue' object has no attribute 'join'
Run Code Online (Sandbox Code Playgroud)
我接下来应该尝试什么?
我正在尝试使用端口扫描程序.
import socket
import subprocess
import sys
from datetime import datetime
subprocess.call('clear', shell=True)
remoteServer = input("Enter a remote host to scan: ")
remoteServerIP = socket.gethostbyname(remoteServer)
print( "-" * 60)
print( "Please wait, scanning remote host", remoteServerIP)
print( "-" * 60)
t1 = datetime.now()
try:
for port in range(1,1025):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((remoteServerIP, port))
if result == 0:
print( "Port {}: Open".format(port))
sock.close()
except KeyboardInterrupt:
print( "You pressed Ctrl+C")
sys.exit()
except socket.gaierror:
print( 'Hostname could not be resolved. …Run Code Online (Sandbox Code Playgroud) 对于tensorflow,我是新手,我正在学习
https://www.tensorflow.org/get_started/get_started
fixW = tf.assign(W, [-1.])
Run Code Online (Sandbox Code Playgroud)
工作正常,但是
fixb = tf.assign(b, [1.])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milenko/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 272, in assign
return ref.assign(value)
AttributeError: 'Tensor' object has no attribute 'assign'
Run Code Online (Sandbox Code Playgroud)
另一个例子
zero_tsr = tf.zeros([1.,2.])
zero_tsr
<tf.Tensor 'zeros:0' shape=(1, 2) dtype=float32>
Run Code Online (Sandbox Code Playgroud)
如果我尝试更改zero_tsr
fixz = tf.assign(zero_tsr, [2.,2.])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milenko/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 272, in assign
return ref.assign(value)
AttributeError: 'Tensor' object has no attribute 'assign'
Run Code Online (Sandbox Code Playgroud)
同样,同样的问题.
我没有改变shell,一切都是一样的.为什么我这里有问题?
我玩了一点
import tensorflow as tf
x = tf.Variable([1.0, 2.0])
initializer = tf.global_variables_initializer()
session.run(initializer)
x
<tf.Variable 'Variable:0' shape=(2,) dtype=float32_ref>
y = 2 * x
y
<tf.Tensor 'mul:0' shape=(2,) dtype=float32>
z = y + 1
z
<tf.Tensor 'add:0' shape=(2,) dtype=float32>
v = session.run(x)
sess.run(initializer)
v = sess.run(x)
print (v)
[ 1. 2.]
v1 = sess.run(z)
print (v1)
[ 3. 5.]
v = sess.run(x)
Run Code Online (Sandbox Code Playgroud)
我有3个变量x,y,z.是否可以显示使用提示中的一个命令定义的所有变量?如果我尝试Jonas的建议
new = tf.trainable_variables()
print (new)
[<tf.Variable 'Variable:0' shape=(2,) dtype=float32_ref>]
Run Code Online (Sandbox Code Playgroud) items = ['a', 'b', 'c','d']
from itertools import permutations
for p in permutations(items):
p1=(''.join(p))
p2=filter(lambda x: x[1]=='b',p1)
Run Code Online (Sandbox Code Playgroud)
我想在第二个索引上用b排除字符串.当我尝试打印过滤器对象时
<filter at 0x7f8d729ba908>
for p in p2:
print (p)
IndexError Traceback (most recent call last)
<ipython-input-27-fbcaa516953f> in <module>()
----> 1 for p in p2:
2 print (p)
<ipython-input-23-c6289753f791> in <lambda>(x)
1 for p in permutations(items):
2 p1=(''.join(p))
----> 3 p2=filter(lambda x: x[1]=='b',p1)
IndexError: string index out of range
Run Code Online (Sandbox Code Playgroud)
lambda是正确的选择吗?为什么我有字符串索引问题?
我想检查是否以正确的方式将csv文件导入MySQL数据库。
import MySQLdb
mydb = MySQLdb.connect(host = 'localhost',user = 'milenko',passwd = 'nuklear',db = 'mm')
cur = mydb.cursor()
command = cur.execute('SELECT * FROM jul')
results = command.fetchall()
print (results)
Run Code Online (Sandbox Code Playgroud)
但是我明白了
File "b12.py", line 6, in <module>
results = command.fetchall()
AttributeError: 'int' object has no attribute 'fetchall'
Run Code Online (Sandbox Code Playgroud)
我看过以前的SO帖子,人们声称数字对象没有fetcall对象。如何一次性删除数据库内容?
我有字典
from collections import OrderedDict
md = {"r3":"piz","r1":"pic","r9":"piz","r12":"pic","r19":"lia","r2":"kurcc","r21":"jes","r99":"pic","r111":"kurcc","r116":"kurcc","r211":"ar","r221":"buc"}
print (OrderedDict(sorted(md.items(), key=lambda t: t[0])))
Run Code Online (Sandbox Code Playgroud)
我想从最低的数字中对它进行排序.但是我得到了
OrderedDict([('r1', 'pic'), ('r111', 'kurcc'), ('r116', 'kurcc'), ('r12', 'pic'), ('r19', 'lia'), ('r2', 'kurcc'), ('r21', 'jes'), ('r211', 'ar'), ('r221', 'buc'), ('r3', 'piz'), ('r9', 'piz'), ('r99', 'pic')])
Run Code Online (Sandbox Code Playgroud)
我应该如何更改代码以使r1,r2,r3顺序?
我的Python3代码
def ask():
while True:
try:
n = input('Input an integer: ')
except:
print ('An error occurred! Please try again!')
continue
else:
break
print ('Thank you, you number squared is: ', n**2)
Run Code Online (Sandbox Code Playgroud)
如果我想取一个数字的正方形,为什么会出错?
unsupported operand type(s) for ** or pow(): 'str' and 'int'
Run Code Online (Sandbox Code Playgroud)
从命令行没问题
>>> 3**2
9
Run Code Online (Sandbox Code Playgroud) python ×9
python-3.x ×3
tensorflow ×2
airflow ×1
dictionary ×1
lambda ×1
mysql ×1
mysql-python ×1
sockets ×1