如何在Python中查找下周六的日期?最好使用datetime和格式为'2013-05-25'?
如果我的清单是
[('IL', 36), ('NJ', 81), ('CA', 81), ('DC', 52), ('TX', 39)],
我该如何排序才能得到结果
[('CA', 81), ('NJ', 81), ('DC', 52), ('TX', 39), ('IL', 36)]?
我们遇到了一个小问题,这让我们很烦恼.让我快速解释一下我们在做什么:
我们正在创建一个Windows窗体,将其另存为.DLL并加载一个MDIContainer.看起来很好,工作正常,但是,如果我们在Form中使用Panel作为组件,它会改变大小.
之前:

之后(在MDIContainer中):

(注意面板!).
我们猜测这是因为我们的自定义MDI容器.这是我们的MDI容器的代码:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NAMESPACE.Forms
{
class MdiClientPanel : Panel
{
private Form mdiForm;
private MdiClient ctlClient = new MdiClient();
public MdiClientPanel()
{
this.ctlClient.BackColor = Color.LightGray;
base.Controls.Add(this.ctlClient);
}
public Form MdiForm
{
get
{
if (this.mdiForm == null)
{
this.mdiForm = new Form();
System.Reflection.FieldInfo field = typeof(Form).GetField("ctlClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
field.SetValue(this.mdiForm, this.ctlClient);
}
return this.mdiForm;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?谢谢你的帮助.
//编辑:添加了赏金,因为我们想知道为什么会这样.你如何重现它:
我想知道标准库中是否有一个函数可以打印任何打印函数并将其作为字符串返回.似乎应该有,但如果它在那里我不是在寻找正确的位置.
我的情况是我做了一个编程练习,创建(经过一些计算)存储在列表中的一串数字,例如,
digits=[1, 0, 0, 1, 0, 1, 0, 0, 0, 1]
Run Code Online (Sandbox Code Playgroud)
和小数点的位置 dp=4
我想把它变成看起来像小数的东西.打印功能可以很好地显示我想要的内容:
print(*(digits[:dp + 1] + ['.'] + digits[dp + 1:]), sep='')
Run Code Online (Sandbox Code Playgroud)
产生 10010.10001
但如果我想以字符串形式返回此结果,我似乎必须编写其他代码.并不是说它很难,但如果已经内置了某些内容则没有必要.打印,格式或%运算符似乎都没有.我能找到的最接近的是StringIO类,但我希望能有一些简单而且不那么神秘的东西.
在Python 3.x中有没有办法创建一个新类型?我只能找到用c ++做的方法.
基本上我想要做的是创建一个词法分析器,我扫描输入和python已经可以做int和字符串,但如果我想要另一个数据类型,如名称,我怎么能分配它,以便我可以做...
EX)
# This can be done
>>> a = "string"
>>> type(a)
<class, 'str'>
# How can I do this?
>>> b = myName
>>> type(myName)
<class, 'name'>
Run Code Online (Sandbox Code Playgroud) 请注意,当您将 pandas.cut 输入到数据框中时,您会在输出中获得每个元素的 bin、Name:、Length:、dtype: 和 Category。我只想为我打印类别数组,这样我就可以获得我正在寻找的垃圾箱数量的范围。例如,将 bins=4 输入到数字“1,2,3,4,5”的数据帧中,我希望输出仅打印四个 bin 的范围,即 (1, 2], (2, 3], (3, 4], (4, 5]。
无论如何我可以做到这一点吗?它可以是任何东西,即使它不需要打印“类别”。
我试图弄清楚一个非常简单的问题,但我仍然无法得到一个类如何工作.例如,如果我想用名为"name"的属性创建一个名为"Friend"的类,这是否意味着我必须在其他任何事情之前给出一个名为"name"的变量?那么我如何定义构造函数以允许"名称"的规范?这段代码是胡说八道吗?提前感谢您的回复
class Friend:
def __init__(self,name):
self.set_name(name)
def set_name(self,name):
self.name=name
def get_name(self):
return self.name
Run Code Online (Sandbox Code Playgroud) 每当我运行我创建的计算器程序时,它工作正常,但文本"无"一直出现,我不知道为什么.这是代码:
def add():
print 'choose 2 numbers to add'
a=input('add this')
b=input('to this')
print a+b
return menu()
def sub():
print 'choose 2 numbers to subract'
a=input('subract this')
b=input('from this')
print b-a
return menu()
def menu():
print "hello, Welcome"
print "these are your options"
print "1. add"
print "2. sub"
print menu()
loop=2
def sys():
while loop==2:
a=input("please choose")
if a==1:
print add()
elif a==2:
print sub()
else:
return menu(),sys()
print sys()
Run Code Online (Sandbox Code Playgroud)
这是输出:
hello, Welcome
these are your options
1. add …Run Code Online (Sandbox Code Playgroud) 我有这个..
the_tuple = (1,2,3,4,5)
print ('\"',the_tuple[1],'\"')
Run Code Online (Sandbox Code Playgroud)
展示
" 2 "
Run Code Online (Sandbox Code Playgroud)
如何才能显示输出"2"?
所以似乎有一些关于gfortran的线宽限制的问题,但不是关于ifort的一个问题.编译时我遇到以下问题:
../../../src/70_gw/gwls_lineqsolver.F90(298): error #5082: Syntax error, found IDENTIFIER 'ENDIF' when expecting one of: ( * ) :: , <END-OF-STATEMENT> ; + . - (/ [ : ] /) ' ** / // > ...
&" endif
----------^
../../../src/70_gw/gwls_lineqsolver.F90(298): error #6404: This name does not have a type, and must have an explicit type. [ENDIF]
&" endif
----------^
../../../src/70_gw/gwls_lineqsolver.F90(297): warning #6043: This Hollerith or character constant is too long and cannot be used in the current numeric context. ['=# of valence …Run Code Online (Sandbox Code Playgroud) python ×8
python-3.x ×4
bins ×1
c# ×1
categories ×1
class ×1
datetime ×1
fortran ×1
list ×1
pandas ×1
python-2.7 ×1
range ×1
sorting ×1
types ×1