Get just a class name without module, etc

This question already has an answer here: Getting the class name of an instance in Python 8 answers 尝试这个: instance.__class__.__name__

获取没有模块的类名等

这个问题在这里已经有了答案: 在Python 8中获取实例的类名答案 尝试这个: instance.__class__.__name__

How to get the concrete class name as a string?

This question already has an answer here: Getting the class name of an instance in Python 8 answers instance.__class__.__name__ 例: >>> class A(): pass >>> a = A() >>> a.__class__.__name__ 'A' <object>.__class__.__name__ you can also create a dict with the classes themselves as keys, not necessarily the classnames typefunc={ int:lambda x: x*2, s

如何将具体的类名称作为字符串?

这个问题在这里已经有了答案: 在Python 8中获取实例的类名答案 instance.__class__.__name__ 例: >>> class A(): pass >>> a = A() >>> a.__class__.__name__ 'A' <object>.__class__.__name__ 你也可以用类自身作为键创建一个字典,不一定是类名 typefunc={ int:lambda x: x*2, str:lambda s:'(*(%s)*)'%s } def transform (param): print typefunc[type(param)](par

Return inherited Python class based on C++ return types

Let's say I have wrapped my C++ classes Foo and Bar and can access them from Python just fine through the SWIG generated module wrap_py : // C++ class Bar { int i; Bar(int i) { this.i = i; } } class Foo { public: Foo(Bar* bar) { this.bar = bar; } Bar* GetBar() { return this.bar; } private: Bar* bar; } In Python, I created my user facing class that are a shallow proxy

返回基于C ++返回类型的继承的Python类

比方说,我已经封装了我的C ++类Foo和Bar并且可以通过SWIG生成的模块wrap_py从Python访问它们: // C++ class Bar { int i; Bar(int i) { this.i = i; } } class Foo { public: Foo(Bar* bar) { this.bar = bar; } Bar* GetBar() { return this.bar; } private: Bar* bar; } 在Python中,我创建了面向类的用户,它们是浅层代理,主要是添加文档字符串,并允许IDE在参数名称上完成标签填充: // Python

Why does "not(True) in [False, True]" return False?

If I do this: >>> False in [False, True] True That returns True . Simply because False is in the list. But if I do: >>> not(True) in [False, True] False That returns False . Whereas not(True) is equal to False : >>> not(True) False Why? Operator precedence 2.x, 3.x. The precedence of not is lower than that of in . So it is equivalent to: >>> not

为什么在[False,True]中不是(True)“返回False?

如果我这样做: >>> False in [False, True] True 这返回True 。 只是因为False在列表中。 但是,如果我这样做: >>> not(True) in [False, True] False 这返回False 。 而not(True)等于False : >>> not(True) False 为什么? 运算符优先级 2.x,3.x. 优先级not低于in 。的优先级。 所以它相当于: >>> not (True in [False, True]) False 这是你想要的: >>> (n

Simple Inherit from class in Python throws error

Hi I just started with Python, I'm currently developing a UI testing application for mobile devices and I have to work on a custom rendered Softkeyboard. Button.py class Button(): def __init__(self, name, x, y, x2=None, y2=None): self.name = name self.x = x self.y = y self.x2 = x2 self.y2 = y2 KeyboardKey.py import Button class KeyboardKey(Butto

简单从Python中的类继承将引发错误

您好,我刚刚开始使用Python,目前我正在开发面向移动设备的UI测试应用程序,并且必须使用自定义渲染软键盘。 Button.py class Button(): def __init__(self, name, x, y, x2=None, y2=None): self.name = name self.x = x self.y = y self.x2 = x2 self.y2 = y2 KeyboardKey.py import Button class KeyboardKey(Button): def __init__(self, name, x, y): super(s

python: write input to file and save it

So, I started doing some python recently and I have always like to lift some weights as well. Therefore, I was thinking about a little program where I can put in my training progress (as some kind of python excercise). I do something like the following as an example: from sys import argv file = argv[1] target_file = open(file, 'w') weigth = raw_input("Enter what you lifted today: ") weigth_li

python:将输入写入文件并保存

所以,我最近开始做一些python,我也一直喜欢举一些权重。 因此,我正在考虑一个可以放入我的训练进度的小程序(就像某种python练习)。 作为一个例子,我做了如下的事情: from sys import argv file = argv[1] target_file = open(file, 'w') weigth = raw_input("Enter what you lifted today: ") weigth_list = [] weigth_list.append(weigth) file.write(weigth_list) file.close() 现在,我知道这里有很多错误,但这

Python. How to create a local datetime with datetime.today()

The server sends a string that I striptime and keep in a variable called here time_from_frontend and then add a tzinfo like this: import pytz my_timezone = pytz.timezone("America/Guayaquil") A = time_from_frontend.replace(tzinfo=my_timezone) print A print A.tzinfo B = (datetime.datetime.today()).replace(tzinfo=my_timezone) print B print B.tzinfo print B - A ?¿

蟒蛇。 如何使用datetime.today()创建本地日期时间

服务器发送一个字符串,我将striptime保存在一个名为time_from_frontend的变量中,然后添加一个tzinfo,如下所示: import pytz my_timezone = pytz.timezone("America/Guayaquil") A = time_from_frontend.replace(tzinfo=my_timezone) print A print A.tzinfo B = (datetime.datetime.today()).replace(tzinfo=my_timezone) print B print B.tzinfo print B - A ?¿ 为什么我在A和B之间

calculate difference between two time in hour

I want to calculate difference between two time in hours using django in sql db the time are stored in timefield. I tried this: def DesigInfo(request): # attendance summary emplist = models.staff.objects.values('empId', 'name') fDate = request.POST.get('fromDate') tDate = request.POST.get('toDate') if request.GET.get('empId_id'): sel = attendance.objects.filter(empId_id=request.G

计算两小时之间的差异

我想计算两个时间之间的差异使用django在sql db的时间存储在时间字段。 我试过这个: def DesigInfo(request): # attendance summary emplist = models.staff.objects.values('empId', 'name') fDate = request.POST.get('fromDate') tDate = request.POST.get('toDate') if request.GET.get('empId_id'): sel = attendance.objects.filter(empId_id=request.GET.get('empId_id'),) for i in sel: #

when does `datetime.now(pytz

delorean docs show this way to get the current time in a given timezone using datetime : from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) and compare it with the delorian-based code: from delorean import Delorean EST = "US/Eastern" d = Delorean(time

何时`datetime.now(pytz

delorean文档以这种方式显示使用datetime获取给定时区中的当前时间: from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) 并将其与基于delorian的代码进行比较: from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) 我相信datetime例子应

Python get current time in right timezone

This question already has an answer here: Display the time in a different time zone 6 answers To get the current time in the local timezone as a naive datetime object: from datetime import datetime naive_dt = datetime.now() If it doesn't return the expected time then it means that your computer is misconfigured. You should fix it first (it is unrelated to Python). To get the current

Python在正确的时区获得当前时间

这个问题在这里已经有了答案: 在不同时区显示时间6个答案 将本地时区中的当前时间作为天真的日期时间对象获取: from datetime import datetime naive_dt = datetime.now() 如果它没有返回预期的时间,那么这意味着您的计算机配置错误。 你应该首先解决它(它与Python无关)。 以UTC的当前时间作为天真的日期时间对象: naive_utc_dt = datetime.utcnow() 在Python 3.3+中获取当前时间作为一个知晓的日期时间对象: