我想首先指出这个问题可能看似重复,但事实并非如此.我在这里看到的所有问题都是关于Python 3的pip,我在谈论Python 3.6.当时使用的步骤不适用于Python 3.6.
apt-get update
apt-get install python3.6
apt-get install python3-pip
pip3 install requests bs4
python3.6 script.py
得到ModuleNotFoundError
以下:
Traceback (most recent call last):
File "script.py", line 6, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Run Code Online (Sandbox Code Playgroud)
我在机器中的Python和pip:
python3
python3.5
python3.5m
python3.6
python3m
python3-config
python3.5-config
python3.5m-config
python3.6m
python3m-config
pip
pip3
pip3.5
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习argparse以便在我的程序中使用它,语法应该是这样的:
-a --aLong <String> <String>
-b --bLong <String> <String> <Integer>
-c --cLong <String>
-h --help
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
#!/usr/bin/env python
#coding: utf-8
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Lorem Ipsum')
parser.add_argument('-a','--aLong', help='Lorem Ipsum', required=False)
parser.add_argument('-b','--bLong', help='Lorem Ipsum', required=False)
parser.add_argument('-c','--cLong', help='Lorem Ipsum', required=False)
parser.add_argument('-h','--help', help='Lorem Ipsum', required=False)
parser.parse_args()
Run Code Online (Sandbox Code Playgroud)
问题是,我在官方文档中看过,看过YouTube视频等,但我无法理解如何确定"主要参数"的"子参数"的数量?
示例:myApp.py -b Foobar 9000
,如何设置-b
必须有两个"子参数",如何获取值,Foobar
和9000
?
还有一个疑问,我知道我可以设置一个参数是否存在required
,但是我想让我的程序只在至少传递一个参数时才执行,所提到的四个参数中的任何一个.
也许这是一个愚蠢的问题,但对不起,我无法理解,希望有人在这里有"老师的力量"来解释它.
我在Python 3.5.1上,使用请求,相关部分代码如下:
req = requests.post(self.URL, data={"username": username, "password": password})
self.cookies = {"MOODLEID1_": req.cookies["MOODLEID1_"], "MoodleSession": req.cookies["MoodleSession"]}
Run Code Online (Sandbox Code Playgroud)
self.URL
有正确的页面,并且 POST 按预期工作,我做了一些打印来检查,它通过了。
我的输出:
Traceback (most recent call last):
File "D:/.../main.py", line 14, in <module>
m.login('first.last', 'pa$$w0rd!')
File "D:\...\moodle2.py", line 14, in login
self.cookies = {"MOODLEID1_": req.cookies["MOODLEID1_"], "MoodleSession": req.cookies["MoodleSession"]}
File "D:\...\venv\lib\site-packages\requests\cookies.py", line 287, in __getitem__
return self._find_no_duplicates(name)
File "D:\...\venv\lib\site-packages\requests\cookies.py", line 345, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='MOODLEID1_', domain=None, path=None"
Run Code Online (Sandbox Code Playgroud)
我正在尝试在运行时进行调试以检查req.cookies
有什么。但我得到的结果是令人惊讶的,至少对我来说。如果你设置一个断点self.cookies = {...}
并运行[(c.name, c.value, …
我知道用户可以通过以下方式更改首选项中的font_face:
"font_face": "gohufont-11",
"font_size": 11,
Run Code Online (Sandbox Code Playgroud)
但是,每次我尝试添加(已安装的)非系统字体,如上面的Gohufont,它都不起作用.
我有一个 Outlook 文件夹,我们称之为LoremIpsum
,其中有 1000 多个电子邮件草稿,我想对其进行枚举并通过 PowerShell 进行一些过滤。我可以使用以下脚本访问该文件夹并查看电子邮件:
Function HandleRemaining {
[CmdletBinding()]
Param()
BEGIN {
Clear-Host
}
PROCESS {
$outlook = New-Object -ComObject outlook.application
$mapi = $outlook.getnamespace("MAPI");
$email = $mapi.Folders.Item(1).Folders.Item('LoremIpsum').Items(1)
foreach ($recip in $email.Recipients) {
$recip
}
$email.To
$email.CC
}
END {
}
}
HandleRemaining
Run Code Online (Sandbox Code Playgroud)
问题是,既不$recip
也不$email.To
返回的电子邮件地址To
或者CC
是电子邮件,而不是我得到这个人的解析名称,例如:
Application : Microsoft.Office.Interop.Outlook.ApplicationClass
Class : 4
Session : Microsoft.Office.Interop.Outlook.NameSpaceClass
Parent : System.__ComObject
Address : /o=ExchangeLabs/ou=Exchange Administrative Group (ALPHA-NUMERIC)/cn=Recipients/cn=LONG-ALPHANUMERIC-HERE
AddressEntry : System.__ComObject
AutoResponse :
DisplayType : …
Run Code Online (Sandbox Code Playgroud) 我试图在Python中实现Luhn公式,这是我的代码:
import sys
def luhn_check(number):
if number.isdigit():
last_digit = int(str(number)[-1])
reverse_sequence = list(int(d) for d in str(int(number[-2::-1])))
for i in range(0, len(reverse_sequence), 2):
reverse_sequence[i] *= 2
for i in range(len(reverse_sequence)):
if reverse_sequence[i] > 9:
reverse_sequence[i] -= 9
sum_of_digits = 0
for i in range(len(reverse_sequence)):
sum_of_digits += reverse_sequence[i]
result = divmod(sum_of_digits, 10)
if result == last_digit:
print("[VALID] %s" % number)
else:
print("[INVALID] %s" % number)
quit()
print("[ERROR] \" %s \" is not a valid sequence." % number)
quit()
def …
Run Code Online (Sandbox Code Playgroud) 假设我有两个Arraylists.
a.add("Isabella");
a.add("Angelina");
a.add("Pille");
a.add("Hazem");
b.add("Isabella");
b.add("Angelina");
b.add("Bianca");
a.retainAll(b);
Run Code Online (Sandbox Code Playgroud)
这应该给我Arraylist a以下元素:Isabella, Angelina, Pille, Hazem
.但是,当我尝试时,a.size()
我得到0.为什么?
我的输出:
[DEBUG] The Karate Kid
[DEBUG] The Day the Earth Stood Still
[DEBUG] The Pursuit of Happyness
[DEBUG] Justin Bieber: Never Say Never
[DEBUG] After Earth
[DEBUG] Independence Day
[DEBUG] Men in Black
[DEBUG] Men in Black II
[DEBUG] Hancock
[DEBUG] Shark Tale
[DEBUG] Made in America
[DEBUG] Six Degrees of Separation
[DEBUG] Jersey Girl
[DEBUG] The Legend of Bagger Vance
[DEBUG] …
Run Code Online (Sandbox Code Playgroud) 我的代码中有以下行:
this.date = new Date(year, month, day);
Run Code Online (Sandbox Code Playgroud)
但是当我给出时,例如:
year = 2008
month = 1
day = 20
Run Code Online (Sandbox Code Playgroud)
我明白了:
Thu Feb 20 00:00:00 BRT 3908
Run Code Online (Sandbox Code Playgroud)
或者让我们说:
year = 2008
month = 3
day = 9
Run Code Online (Sandbox Code Playgroud)
我明白了:
Thu Apr 09 00:00:00 BRT 3908
Run Code Online (Sandbox Code Playgroud)
有什么想法有什么不对吗?
python ×3
java ×2
python-3.x ×2
argparse ×1
arraylist ×1
checksum ×1
cookies ×1
date ×1
email ×1
install ×1
luhn ×1
mapi ×1
math ×1
outlook ×1
pip ×1
powershell ×1
sublimetext2 ×1
sublimetext3 ×1
ubuntu ×1