我想为我的代码安装模块'mutagen'和'gTTS',但我想拥有它,所以它会在没有它们的每台计算机上安装模块,但如果没有它们,它将不会尝试安装它们.他们已经安装好了.我目前有:
def install(package):
pip.main(['install', package])
install('mutagen')
install('gTTS')
from gtts import gTTS
from mutagen.mp3 import MP3
Run Code Online (Sandbox Code Playgroud)
但是,如果您已经拥有这些模块,那么只要您打开它,就会在程序启动时添加不必要的混乱.
垂直滚动对我来说在 Eclipse 中工作得很好,水平滚动在其他任何地方都可以完美工作,但由于某种原因,在 Eclipse 中水平滚动不起作用。每当我想查看一行不适合可见区域的代码时,我都必须手动将光标移到项目底部并拖动滚动条。这不是一个大问题,但它确实变得非常烦人。有人知道怎么修这个东西吗?我使用的是 Eclipse 版本 2018-09 (4.9.0) 和 Windows 10 版本 1803,如果这有什么不同的话。
我正在使用 Python 包未检测到的 Chromedriver,因为我需要能够使用 webdriver 登录 Google 帐户,并且我想将选项传递{"credentials_enable_service": False, "profile.password_manager_enabled": False}给驱动程序,这样它就不会弹出保存密码的弹出窗口。我试图使用以下方法传递这些选项:
import undetected_chromedriver.v2 as uc
uc_options = uc.ChromeOptions()
uc_options.add_argument("--start-maximized")
uc_options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False})
driver2 = uc.Chrome(options=uc_options)
Run Code Online (Sandbox Code Playgroud)
这个参数--start-maximized工作得很好,如果我运行代码,它就会按预期最大化。但是,当添加实验选项并运行代码时,它会返回错误:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs
Run Code Online (Sandbox Code Playgroud)
所以我想我应该尝试将参数作为所需的功能传递,从而编写代码:
import undetected_chromedriver.v2 as uc
uc_options = uc.ChromeOptions()
uc_options.add_argument("--start-maximized")
uc_options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False})
uc_caps = uc_options.to_capabilities()
driver2 = uc.Chrome(desired_capabilities=uc_caps)
Run Code Online (Sandbox Code Playgroud)
虽然此代码运行并且不会生成任何错误,但它也根本不执行任何操作。密码弹出窗口仍然显示,驱动程序甚至没有启动最大化,尽管后一部分可以作为一个选项。
所以我的问题是:如何正确地将所需的功能传递给未检测到的 Chromedriver?或者,或者:如何正确地将实验选项传递给未检测到的 Chromedriver?
python selenium python-3.x selenium-webdriver undetected-chromedriver
我已经使用Pyinstaller将我的程序(用Python 3.6.1编写,使用Python 3.5.3转换)从.py转换为.exe.然而,它在加载时非常慢(大约需要16秒,相比之下,在IDLE运行时<1秒),即使我优化了我的问题所在(导入大量模块,所以我将代码更改为仅导入必要的模块部分.在IDLE中运行它时加速了很多,但当我创建一个.exe时,它完全相同(我确实检查过我使用的是正确的.py文件).我似乎Pyinstaller只是将您安装在系统上的所有模块打包到.exe中,而不是只包含实际使用的模块的小部分(使用时--onefile).我如何确保Pyinstaller只安装模块的必要部分或以其他方式加速,同时仍然使用--onefile并将其打包成单个.exe?
完整代码:
from os import path, remove
from time import sleep
from sys import exit
from getpass import getuser
from mmap import mmap, ACCESS_READ
my_file = "Text To Speech.mp3"
username = getuser()
no_choices = ["no", "nah", "nay", "course not", "don't", "dont", "not"]
yes_choices = ["yes", "yeah", "course", "ye", "yea", "yh", "do"]
def check_and_remove_file():
active = mixer.get_init()
if active != None: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Inno Setup Compiler 创建一个安装文件,我希望它安装到 Documents 文件夹中,因为它需要创建然后删除一个文件,如果它安装到 Program Files 则无法执行此操作。我试过%userprofile%\Documents在文件资源管理器中使用as ,但这只是%userprofile%在 Setup.exe 所在的任何地方创建一个名为的文件夹,并且 C:\Users\%username%\Documents只是%username%在用户文件夹中创建文件夹。无论它在哪里,我如何让它安装到 Documents 文件夹中?
我正在尝试制作一段代码来计算三个不同候选者的投票数,而我正在使用一个使用变量名称(A,B或C)作为参数的函数.
我试图这样做,以便无论何时计算该候选人的投票,它都会调用该函数将该候选人的变量增加1.但是,我已经尝试了所有3个候选人的所有方式总是有0票算了,除非我完全删除了这个功能.
我已经尝试了几种不同的方法来制作变量全局变量,但它们都给出了相同的结果.
A = 0
B = 0
C = 0
def after_vote(letter):
letter = letter + 1
print("Thank you for your vote.")
def winner(winner_letter, winner_votes):
print("The winner was", winner_letter, "with", str(winner_votes), "votes.")
while True:
vote = input("Please vote for either Candidate A, B or C. ").upper()
if vote == "A":
after_vote(A)
elif vote == "B":
after_vote(B)
elif vote == "C":
after_vote(C)
elif vote == "END":
print("Cadidate A got", str(A), "votes, Candidate B got", str(B), "votes, and Candidate C …Run Code Online (Sandbox Code Playgroud) python function global-variables parameter-passing python-3.x
所以我刚开始编写代码,将询问用户,他们希望有一个测试,是多么困难,他们希望它是什么主题,然后,很明显,给他们的考验.我创建了一个检查它是什么测试if语句和多么困难它应该是一个功能,我只是做了一个随机的暴殄天物功能测试代码.我会告诉你代码(显然非常早期的alpha并且远未完成)然后我会解释这个问题.
def which_test(real_dif, real_test, give_test):
if difficulty == real_dif and test == real_test:
give_test
def easy_CS():
print("HEY")
while True:
test = str(input("What test do you want to take? Computer Science, History or Music? ").strip().lower())
difficulty = str(input("Do you want to take the test in easy, medium or hard? ").strip().lower())
which_test("easy", "computer science", easy_CS())
Run Code Online (Sandbox Code Playgroud)
问题是,easy_CS()无论输入变量是什么,函数都会被激活.我可以为test变量输入"JFAWN",为变量输入"JDWNA" difficulty,它仍然会打印"HEY".我如何使它实际上取得变量,或者我怎样才能使它按照预期的方式工作?
python ×5
python-3.x ×5
function ×2
eclipse ×1
exe ×1
inno-setup ×1
installation ×1
module ×1
performance ×1
pyinstaller ×1
selenium ×1
variables ×1
while-loop ×1