我有一个共享的python库,我在多个项目中使用,所以结构如下所示:
Project1
main.py <--- (One of the projects that uses the library)
...
sharedlib
__init__.py
ps_lib.py
another.py
Run Code Online (Sandbox Code Playgroud)
现在在每个项目的main.py中,我使用以下hack来使它工作:
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import sharedlib.ps_lib
...
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用这个黑客的情况下做到这一点?或者有更好的方法来组织项目结构吗?
python directory-structure project-structure organization python-import
嘿我正在尝试执行以下命令(使用psutil.Popen和python 2.7):
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" "C:\docs\?.xlsm"
Run Code Online (Sandbox Code Playgroud)
使用此代码:
dir = u"C:\\docs"
doc = os.listdir(dir)[0]
full_path = os.path.join(dir, doc)
command = u"\"C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE\" \"{}\"".format(full_path)
process = psutil.Popen(command)
Run Code Online (Sandbox Code Playgroud)
但我得到了这个例外:
process = psutil.Popen(command)
File "C:\Python27\lib\site-packages\psutil\__init__.py", line 1370, in __init__
self.__subproc = subprocess.Popen(*args, **kwargs)
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u05ea' in position 102: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我找到了这个相关的问题: subprocess.Popen有一个unicode路径.但是每一个给出的答案都不适用于我.
使用subprocess.Popen(command.encode(locale.getpreferredencoding()))会抛出以下异常:
Traceback (most recent …Run Code Online (Sandbox Code Playgroud) 我最近遇到了一个不寻常的问题,当我打开一些excel/word文档并尝试连接到它的进程时使用 -
app = pywinauto.Application(backend="uia").connect(process=19812)
Run Code Online (Sandbox Code Playgroud)
它似乎不起作用,这意味着app.is_process_running()返回False,top_window()方法引发RuntimeError(找不到该进程的窗口)异常.
但是,如果我运行实际的可执行程序(Winword.exe或Excel.exe而不是某些*.xls文件),它似乎工作正常,一切似乎工作正常.
我在文件上检查了UIA与inspect.exe的兼容性,一切似乎都没问题.
这可能是什么问题?
如何配置使用多重处理(multiprocessing.Pool.map)的python模块,以便每个生成的进程也逐行进行配置。
目前,我使用line_profiler进行性能分析,但它不支持多处理。有手动方法吗?或者也许使用其他工具?
我有一台使用 RabbitMQ 运行 Celery 的服务器。但是当我尝试使用 send_task 发送任务时,它只返回一个 AsyncResult 对象。
但实际任务没有运行(即使工作人员和队列为空)
c = Celery("tasks", broker="amqp://guest@127.0.0.1//")
c.send_task("tasks.printing.test_print", (100), queue="print_queue", routing_key="printing.test_print")
Run Code Online (Sandbox Code Playgroud)
我的芹菜配置是:
CELERY_QUEUES = (
Queue('default', routing_key='task.#'),
Queue('print_queue', routing_key='printing.#'),
)
CELERY_DEFAULT_EXCHANGE = 'tasks'
CELERY_ROUTES = {
'tasks.printing.test_print': {
'queue': 'print_queue',
'routing_key': 'printing.test_print',
}}
BROKER_URL = 'amqp://'
Run Code Online (Sandbox Code Playgroud)
我只执行一名工人:
celery -A celerymain worker --loglevel=debug
Run Code Online (Sandbox Code Playgroud)
这是它的初始日志:
- ** ---------- [config]
- ** ---------- .> app: __main__:0x7eff96903b50
- ** ---------- .> transport: amqp://guest:**@localhost:5672//
- ** ---------- .> results: amqp://
- *** --- * --- .> concurrency: 4 …Run Code Online (Sandbox Code Playgroud) 我们有一个需要在许多项目之间共享的python库,我们正在尝试找到一种方法来组织和链接共享库到想要使用它的特定项目.
它还需要在没有visual studio的情况下工作,这意味着如果将整个项目移动到某个不同的机器上,它仍然可以工作并使用"共享库",这意味着链接库需要静态放置在每个使用的项目中它(当然每次更新时,库目录都会在每个项目中更新)
无论如何它可以做到吗?
目录结构如下所示:
Project1
main.py <--- (One of the projects that uses the library)
...
Libs
PyLib <--- (This is the shared library)
__init__.py
ps_lib.py
another.py
CWinLib
CNixLib
Run Code Online (Sandbox Code Playgroud)
我测试的一些方法是:
使用链接文件 - 问题是它不会将整个包复制到项目中(这意味着它不能在visual studio之外工作)
添加搜索路径 - 与以前相同的问题,在visual studio之外无效
使用sys.path.append - 这意味着我们需要复制确切的目录结构,这是我想要避免的
还有另一种解决方法吗?
python projects-and-solutions visual-studio ptvs visual-studio-2017
有没有办法使用 pywinauto获取窗口的属性,例如: title和control_type ?
因为看起来您可以通过它们搜索窗口,但是没有指向这些属性的窗口属性。
我正在尝试滚动 Excel 文档(使用 pywinauto),但它似乎不起作用。
代码:
app = Application(backend="uia").connect(process=8876)
win = app.top_window()
win.set_focus()
win.wheel_mouse_input(wheel_dist=10)
Run Code Online (Sandbox Code Playgroud)
set_focus有效,但滚动不起作用,我也尝试使用wheel_dist但没有成功。
另一个问题,有没有办法向右/向左滚动?
谢谢。
如何使用“gcloud”命令将文件从谷歌驱动器复制到实例计算机?
我使用 - 授权谷歌驱动器
gcloud auth login --enable-gdrive-access
Run Code Online (Sandbox Code Playgroud)
但我找不到任何有关如何从谷歌驱动器下载文件的信息
python ×8
pywinauto ×3
celery ×1
gcloud ×1
organization ×1
profiling ×1
psutil ×1
ptvs ×1
python-2.x ×1
rabbitmq ×1
subprocess ×1
windows ×1