请注意,我不是在问“如何检查我安装了哪个版本的Python”。
我已经在Windows计算机上安装了多个版本的Python,例如Python 2.7-64,python 2.7-32,Python 3.7-32。
Python 3包含“ py”和“ pyw”,可帮助我轻松启动不同的Python,例如:
我想知道的是,如何检查我在Windows PC上安装了多少个不同版本的Python,它们是什么版本?
PyCharm可以找到它,但是,一方面,我不知道它是否完整,而另一方面,我想知道Python是否提供了任何工具,或者操作系统是否可以做到这一点。
我正在使用Python tkinter。我可以通过设置Radiobutton的属性来自定义背景颜色(使用“bg”属性)和字符颜色(使用“fg”属性)。现在我需要:
所以我创建了一个像这样的单选按钮:
common_bg = '#' + ''.join([hex(x)[2:].zfill(2) for x in (181, 26, 18)]) # RGB in dec
common_fg = '#ffffff' # pure white
Radiobutton(paraent_frame, text='abc', variable=radio_value, value=2,
command=on_click_level_radio, bg=common_bg, fg=common_fg)
Run Code Online (Sandbox Code Playgroud)
GUI看起来像这样(黑色箭头是我自己添加的):
但问题是,单选按钮圆圈的背景是白色的。当用于指示是否选择收音机的“小点”默认为黑色时,效果很好。当我将“fg”属性设置为白色时,“小点”也变成白色,从而无法区分是否选择了无线电。
所以我想知道是否有一种方法可以单独设置单选按钮的“圆圈”或“小点”的颜色。
我刚刚将我的 PyCharm 社区从 2020.3 升级到 2022.3。我曾经通过文件 --> 设置 --> Porject: xxx --> Python Interpreter --> “加号” --> 管理存储库在 PyCharm 中设置私有 PyPI 索引 URL。但该按钮已从 PyCharm Community 2022.3 中删除。
新版 PyCharm 社区 2022.3 没有“管理存储库”按钮:
我用谷歌搜索了这个案例,但找不到答案,似乎大多数文章都假设“管理存储库”按钮仍然存在。我在PyCharm设置搜索框中搜索“管理”,“存储库”,但没有找到这样的配置。我以为“Settings Repository”插件就是我想要的,但似乎这个插件是关于共享IDE设置而不是PyPI索引url。
我在Windows平台上使用PyCharm,详细版本信息是:
PyCharm 2022.3(社区版)内部版本 #PC-223.7571.203,构建于 2022 年 11 月 30 日运行时版本:17.0.5+1-b653.14 amd64 VM:OpenJDK 64 位服务器 VM by JetBrains sro Windows 10 10.0 GC:G1年轻代、G1老代
考虑以下简单的Python代码:
from operator import itemgetter
def main():
my_list = [
('Bob', 'RnD', 10),
('John', 'RnD', 11),
('Mary', 'Sales', 10),
('Linda', 'Sales', 11),
]
# I saw a lot of examples tell people to do multi-fields sorting like this, but
# PyCharm inspector warns it
print(sorted(my_list, key=itemgetter(1, 2), reverse=True))
# I read some articles and found that the following code works, too, without warning.
print(sorted(my_list, key=(lambda x: (x[1], x[2])), reverse=True))
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
对于“ print(sorted(my_list,key = itemgetter(1,2),reverse = True))”行,PyCharm显示以下警告: …
我正在尝试使用 Python 从 JSON 中提取有用信息的不同方法。我尝试了 jsonpath_rw_ext 和 jsonpath_ng。现在我可以使用 jsonpath_rw_ext 但 jsonpath_ng 不起作用。我不想放弃 jsonpath_ng 因为我可能没有以正确的方式使用它。检查以下代码:
import jsonpath_rw_ext
from jsonpath_ng.ext import parse
import json
from pprint import pprint
json_str = '''{
"students": [
{"name": "Peter", "gender": "Male", "age": 20},
{"name": "Mary", "gender": "Female", "age": 30},
{"name": "Susan", "gender": "Female", "age": 40}
],
"teachers": [
{"name": "William", "gender": "Male", "age": 30},
{"name": "John", "gender": "Male", "age": 40},
{"name": "Lucy", "gender": "Female", "age": 50}
]
}'''
json_obj = json.loads(json_str)
print 'jsonpath_rw_ext:'
female_students = jsonpath_rw_ext.match('$.students[?gender=="Female"]', …
Run Code Online (Sandbox Code Playgroud) 我想在一个类中定义一个装饰器.我不想将它定义为一个独立的独立函数,因为这个装饰器专门用于这个类,我想把相关的方法保存在一起.
这个装饰器的目的是检查一些先决条件,尤其是成员变量持有的数据库连接,SSH连接等仍然可用.如果没有,则不会调用修饰函数,并且将执行一些错误报告和清理工作.
我做了以下测试类来测试它是否有效,并且代码确实运行良好.但我发现PyCharm会对这段代码发出警告.所以我想知道,如果这意味着我的代码不是Pythonic,或者PyCharm不够智能并且错误地发出了警告?
如果我的代码不是Pythonic,如何改变?如果是PyCharm的错误,我和我的团队如何配置PyCharm让它特别忽略这种警告,同时保留大部分其他lint检查?
class TestClass:
def __init__(self):
self.flag = True
def dec(func):
def wrapper(self, *args, **kwargs):
if not self.flag:
print("Won't run!")
return empty_fun(self, *args, **kwargs)
return func(self, *args, **kwargs)
def empty_fun(*args, **kwargs):
return None
return wrapper
@dec
def foo(self):
print("foo")
@dec
def bar(self, msg, more, *args, **kwargs):
print("message: %s" % msg)
print("more %s:" % more)
for item in args:
print("other item: %s" % item)
name = kwargs.get('name')
age = kwargs.get('age')
print('name: %s' % name)
print('age: %s' % age)
def …
Run Code Online (Sandbox Code Playgroud) 例如,在Python中我可以做类似的事情:
li = [('John', 20, '360 244 4210'), ('Bill', 22, '360 244 4211'), ('Susan', 19, '360 244 4214')]
for name, age, phone_num in li:
register(name, age)
make_a_call(name, phone_num)
Run Code Online (Sandbox Code Playgroud)
但在 Groovy 中我必须这样做:
li = [['John', 20, '360 244 4210'], ['Bill', 22, '360 244 4211'], ['Susan', 19, '360 244 4214']]
li.each {
name = it[0]
age = it[1]
phone = it[2]
register(name, age)
make_a_call(name, phone_num)
}
Run Code Online (Sandbox Code Playgroud)
Groovy 中有什么方法可以像 Python 一样解包列表吗?