我该如何更改?
我正在寻找类似的东西:
SetMasterVolume(0.5)
SetAppVolume('FooBar',0.5)
Run Code Online (Sandbox Code Playgroud)
我尝试使用 ctypes.windll.winmm,但找不到关于如何使用它的太多文档。
提前致谢。
class MyClass:
var1 = 1
def update(value):
MyClass.var1 += value
def __init__(self,value):
self.value = value
MyClass.update(value)
a = MyClass(1)
Run Code Online (Sandbox Code Playgroud)
我正在尝试更新方法(_ init _)中的类变量(var1),但我给了我:
TypeError: unbound method update() must be called with MyClass instance as first argument (got int instance instead)
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我希望通过调用print MyClass.var1轻松访问类中的所有变量
可能吗?
有些东西:
import win32com.client
ProgID = "someProgramID"
com_object = win32com.client.Dispatch(ProgID)
for methods in com_object:
print methods
Run Code Online (Sandbox Code Playgroud)
我得到了com_object.__dict__
,其中列出:
[_oleobj_, _lazydata_, _olerepr_, _unicode_to_string_, _enum_, _username_, _mapCachedItems_, _builtMethods_]
Run Code Online (Sandbox Code Playgroud)
大多数都是空的,除了:
_oleobj_
(PyIDispatch)_lazydata_
(PyITypeInfo)_olerepr_
(LazyDispatchItem实例)_username_
(<unknown>
)但我不知道如何访问这些类型的任何东西.
我想在我的程序中实现一个嵌套子级别的树,我正在寻找这两种类型中的哪一种(View/Widget)最适合我的目标.
我有一个任务日期列表,其中包括已完成/错过/失败,每个任务都计算完成/错过/失败的次数,最后是当天的分数.
我想像这样显示它们:
我在QtCreator中使用QTreeWidget做了这个例子,但是我担心修改元素很难,因为它们存储在其他地方.
我的担忧是否合理,我应该转到模型/视图结构,还是可以轻松使用QTreeWidget?树将记录任务,因此将不断变化.元素只会添加到它,而不是删除.日期将从最高 - 最低(第2天,第1天,第1天)排序
我有这段代码:
a = "aa"
b = 1
c = { "b":2 }
d = [3,"c"]
e = (4,5)
letters = [a, b, c, d, e]
Run Code Online (Sandbox Code Playgroud)
我想用它做点什么,这会把它们清空.不失其类型.
像这样的东西:
>>EmptyVars(letters)
['',0,{},[],()]
Run Code Online (Sandbox Code Playgroud)
任何提示?
我下载了gammu源文件.我的目标是能够在我的python程序中使用gammu模块.如何运行python-gammu的setup.py安装.我每次尝试都会得到
running install
running build
running build_py
running build_ext
ERROR: Could not find pkg-config!
Run Code Online (Sandbox Code Playgroud) 当代码正在运行时
import requests
monitor_r = requests.get(monitor_url, proxies=proxies, timeout=60*4)
Run Code Online (Sandbox Code Playgroud)
我得到以下例外:
('Connection aborted.', BadStatusLine("''",))
# and
('Cannot connect to proxy.', error(32, 'Broken pipe')))
Run Code Online (Sandbox Code Playgroud)
这些错误是什么以及如何解决?
我有一个在类体中具有查找字典的类,我存储了所有实例和一些键。
当我实例化实例时,我没有将它们保存在任何变量或外部字典中,我将它们存储在这个查找字典中。
当我以某种方式实例化一个已经在 dict 中的实例时,我将它重新分配给 dict 中的一个并更新它,在其他一些函数中使用它的新值和旧值。
我想知道这是否是一个好习惯?或者我应该重构并使其具有保存实例的外部字典。
是否有针对此类行为的 PEP 指南?
例子:
class MyClass:
all_instances = {} # this dictionary is in local space and it's clear that
# the only interaction is with MyClass
def __init__(self, unique_id, x, y, z):
if unique_id not in MyClass.all_instances:
self.unique_id = unique_id
self.x = x
self.y = y
self.z = z
MyClass.all_instances[unique_id] = self
else:
self = MyClass.all_instances[unique_id]
self.update(x, y, z)
def update(self, new_x, new_y, new_z):
self.x = self.do_something_with(self.x, new_x)
self.y = self.do_something_with(self.y, …
Run Code Online (Sandbox Code Playgroud) 说我有这个:
struct Person {
char *name;
char *occupation;
int years_of_service;
float salary;
};
Run Code Online (Sandbox Code Playgroud)
还有这个:
float calculate_salary(struct Person *who){
float basesalary;
char *doctor = "Doctor";
char *janitor = "Janitor";
int job1 = strcmp(who->occupation, doctor);
int job2 = strcmp(who->occupation, janitor);
if(job1 == 0){
basesalary = 10000.0;
}
else if(job2 == 0){
basesalary = 800.0;
}
return basesalary + basesalary*(who->years_of_service*0.1);
}
Run Code Online (Sandbox Code Playgroud)
计算人的工资的正确方法是什么?
在Python中我会在init中执行:
self.salary = self.calculate_salary()
Run Code Online (Sandbox Code Playgroud)
但由于C不是OO,我假设我必须首先创建没有薪水的人,然后设置薪水.像这样:
struct Person *joe = Person_create("Joe Alex", "Doctor",1);
joe->salary = calculate_salary(joe);
Run Code Online (Sandbox Code Playgroud)
但我希望有更好理解C的人告诉我这是否正确.
作为旁注,字符串同情是正确的吗?我发现这很奇怪,我应该使用开关吗?
我很难理解如何使用QTreeView和QStandardItemModel设置多级QTree.
这就是我所拥有的:
from PySide.QtGui import *
import sys
class MainFrame(QWidget):
def __init__(self):
QWidget.__init__(self)
tree = {'root': {
"1": ["A", "B", "C"],
"2": {
"2-1": ["G", "H", "I"],
"2-2": ["J", "K", "L"]},
"3": ["D", "E", "F"]}
}
self.tree = QTreeView(self)
root_model = QStandardItemModel()
self.tree.setModel(root_model)
for r,root in enumerate(sorted(tree)):
root_item = QStandardItem(root)
root_model.setItem(r,root_item)
for c,child in enumerate(sorted(tree[root])):
child_model = QStandardItemModel(root_model)
child_item = QStandardItem(child)
child_model.setItem(c, child_item)
for gc, grand_child in enumerate(sorted(tree[root][child])):
grand_child_model = QStandardItemModel(child_model)
grand_child_item = QStandardItem(grand_child)
grand_child_model.setItem(gc,grand_child_item)
if type(tree[root][child]) == dict:
for …
Run Code Online (Sandbox Code Playgroud)