我在创建初始迁移时遇到问题,该迁移会自动拥有我在models.py中使用共享Base(declarative_base)定义的表.
当我输入命令时:
alembic revision --autogenerate
Run Code Online (Sandbox Code Playgroud)
alembic创建一个空文件.
我的配置或方法有什么问题?
project.base.py:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
Run Code Online (Sandbox Code Playgroud)
env.py:
import sys
import os
sys.path.append(os.path.abspath(os.getcwd()))
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from project.base import Base
target_metadata = Base.metadata
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
# target_metadata.reflect(engine, …Run Code Online (Sandbox Code Playgroud) 我正在与Snakemake合作,但找不到找到当前规则名称的方法。
例如,有没有办法像这样进行访问:
rule job1:
input: check_inputs(rules.current.name)
output: ...
Run Code Online (Sandbox Code Playgroud)
当check_inputs每个规则的功能大致相同时,这将非常有用。
当然,我做到了,它的工作原理是:
rule job1:
input: check_inputs("job1")
output: ...
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否存在一种更多的“ Snakemaker方式”来获取当前规则的名称,以避免每次都编写/硬编码该规则的名称。
任何帮助或建议将不胜感激。
--- EDIT1 ---只有当snakemake解析了and 语句时,才能
访问规则名称。因此在/ 定义中无法使用。{rules.myrule.name}inputoutput{rules.myrule.name}inputoutput
这样做的想法是例如快速访问当前规则的名称{rules.current},因为{rules.myrule.name}它也是重复的。
我正在尝试使用 Python 将 .xlsx 文件中的数据读取到 MySQL 数据库中。
这是我的代码:
wb = openpyxl.load_workbook(filename="file", read_only=True)
ws = wb['My Worksheet']
conn = MySQLdb.connect()
cursor = conn.cursor()
cursor.execute("SET autocommit = 0")
for row in ws.iter_rows(row_offset=1):
sql_row = # data i need
cursor.execute("INSERT sql_row")
conn.commit()
Run Code Online (Sandbox Code Playgroud)
不幸的是,openpyxl'sws.iter_rows()非常缓慢。我已经尝试过使用xlrd和pandas模块的类似方法。还是慢。有什么想法吗?
我需要知道所拍摄图像数据的属性(日,时,小时,分钟,秒)
import exifread
import os
directoryInput=r"C:\tekstilshiki"
for filename in os.listdir(directoryInput):
if filename.endswith('.jpg'):
with open(r"%s\%s" % (directoryInput, "11.jpg"), 'rb') as image: # directory and name bleat
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal'])
# into date and time
day, dtime = dt.split(" ", 1)
hour, minute, second = dtime.split(":", 2)
Run Code Online (Sandbox Code Playgroud)
当您运行脚本Goes错误
回溯(最近一次调用最后一次):文件"C:/tekstilshiki/ffd.py",第8行,在dt = str中(exif ['EXIF DateTimeOriginal'])KeyError:'EXIF DateTimeOriginal'
我假设标签名称不正确
我readdir()在保险丝中实现功能时遇到了一个奇怪的问题.基本上当我ls在保险丝中的任何目录上执行时,我收到一个错误,例如:
#ls
ls:读取目录.:输入/输出错误
file1.c file2.c
但奇怪的是,readdir()它正在做它应该做的事情.在某个意义上,在该特定目录中,我有两个名为的文件file1.c,file2.c并且能够正确读取它.
在调试问题时,我注意到fuse filler函数(fuse_fill_dir_t作为参数传递readdir())可能导致此错误.
这是因为如果我只是使用调试打印目录printf的内容而不使用填充函数返回内容,我没有看到错误.
但是一旦我开始使用填充函数返回内容,我就开始看到这个错误.
我有两个与此相关的问题:
1)任何人都知道为什么filler函数可能导致这个问题?
2)如何查找fuse_fill_dir_t函数代码的定义?我已经通过这种论证查看了大部分保险丝功能但直到现在都没有运气.
任何帮助表示赞赏!
干杯,Vinay
我有这样的模型:
class Test(db.Model, UnicodeMixin):
__tablename__ = 'test'
id = db.Column(db.Integer, primary_key=True)
subject = db.Column(db.String(512), nullable=False)
additional = None
def __unicode__(self):
return u'<Test {0}>'.format(self.id)
Run Code Online (Sandbox Code Playgroud)
有些代码很难SELECT从db中使用其他动态数据来生成RAW SQL 。
例如,它像:
db.session.query(Test).from_statement("SELECT test.id AS test_id, test.subject AS test_subject, 99 AS additional FROM test").all()
Run Code Online (Sandbox Code Playgroud)
它生成python对象的列表Test,但是如何填充additional这些python对象的属性?
我不想在数据库中存储NULL列additional。
我想用SQL创建动态附加数据并将其添加到python对象。
请帮忙。
谢谢。
我正在使用并行python executePipeline多次执行一个大函数().此功能也使用多处理(使用multiprocessing模块).
我使用并行python模块在我的控制台上正确显示日志消息时遇到了一些麻烦.当我不使用它时,日志消息很好地显示.
下面是它的工作原理.我有一个服务器每次从客户端收到请求时都会调用一个worker:
job = self.server.job_server.submit(func = executeWorker, args = (config, ) )
Run Code Online (Sandbox Code Playgroud)
每次有来自客户端的新请求时,都会从新线程执行此函数.然后,worker正在executePipeline使用多处理调用正在执行不同processus 的函数.
SocketServer.TCPServer我使用线程的服务器.我使用根记录器在服务器中设置了一个记录器:
self.logger = logging.getLogger()
self.logger.setLevel(logging.INFO)
self.logger.addHandler(logging.StreamHandler()
self.job_server = pp.Server(ncpus = 8) # for test
self.jobs = []
Run Code Online (Sandbox Code Playgroud)
当我运行我的服务器时,我只能从而executePipeline不是从子进程获取日志记录.此外,我只在作业结束时才记录执行管道,而不是在运行时.
这里还有工人代码.在"Executing pipeline with worker number "很好地显示在我的终端
'''
Setup logging
'''
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# worker name
publicIP = socket.gethostbyname(socket.gethostname())
pid = os.getpid()
workerID = unicode(str(publicIP) + ":" + str(pid))
logger.info( "Executing pipeline with worker {}".format(workerID)) …Run Code Online (Sandbox Code Playgroud) 我相信我没有正确安装我的C编译器.我正在尝试在我的Windows 8机器上安装一些Python 2.7软件包.我一直收到以下错误:
RuntimeError:破坏的工具链:无法链接简单的C程序.
Python安装正确,并且定期运行良好.我一直在使用该virutalenv软件包并在虚拟环境中工作.然后我尝试安装Cygwin,MinGW和MS Visual Studios 2012,这些似乎都没有virtualenv.我不确定我做错了什么,任何帮助都会很棒.
谢谢你,吉米
每次使用 PyAudio 播放声音时,我都会收到错误消息,并且无法抑制它们。
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or …Run Code Online (Sandbox Code Playgroud) 对于 Pandas:df.merge()方法,是他们获取合并摘要统计信息(例如匹配数、不匹配数等)的便捷方法。我知道这些统计数据取决于标志how='inner',但是知道使用内部联接等时“丢弃”了多少内容会很方便。我可以简单地使用:
df = df_left.merge(df_right, on='common_column', how='inner')
set1 = set(df_left[common_column].unique())
set2 = set(df_right[common_column].unique())
set1.issubset(set2) #True No Further Analysis Required
set2.issubset(set1) #False
num_shared = len(set2.intersection(set1))
num_diff = len(set2.difference(set1))
# And So on ...
Run Code Online (Sandbox Code Playgroud)
但认为这可能已经实施了。我是否错过了它(即类似report=True会返回的合并new_dataframe以及报告系列或数据框)
python ×9
pandas ×2
sqlalchemy ×2
alembic ×1
attributes ×1
audio ×1
c ×1
django ×1
dynamic ×1
exif ×1
filesystems ×1
fuse ×1
logging ×1
mysql ×1
openpyxl ×1
pyaudio ×1
python-3.x ×1
snakemake ×1
virtualenv ×1
windows ×1
xlrd ×1