我在使用Lua获取文件大小时遇到问题.我正在创建一个函数方法,如果文件的文件大小是743 bytes,那么该文件将被删除.
这是我的代码:
local getDLFile = function(fileToDL)
local path = system.pathForFile(fileToDL, system.DocumentsDirectory )
local myFile = io.open( path, "w+b" )
http.request{
url = "http://www.testfile.com/"..fileToDL,
sink = ltn12.sink.file(myFile),
}
-- i don't know what is the syntax
if myFile.size == 743 bytes then
myFile.delete
end
end
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决我的情况吗?
如何声明单选按钮的初始值?
form.py
YESNO = (
('Yes','Yes'),
('No', 'No'),
)
class MyForm(forms.Form):
like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO)
Run Code Online (Sandbox Code Playgroud)
myhtml.html
{{form.like}}
Run Code Online (Sandbox Code Playgroud)
我试着把:
like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO, initial={'Yes':'Yes'})
Run Code Online (Sandbox Code Playgroud)
当我运行我的代码时,我的单选按钮尚未选中..
我正在使用Tkinter.
import Tkinter as tk
class App(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
....
root = tk.Tk()
root.title("title")
app = App(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
它有刷新吗?因为我想刷新我的画面.是root.refresh()有可能吗?
我使用Windows 7开发Django 1.3.7,使用PostgreSQL 9.3作为数据库.在我settings.py设置DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2',但当我尝试执行时,python manage.py syncdb我收到此错误:
C:\Django-Proj\myproj\myproj>python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 61, in <module>
execute_manager(settings)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "c:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 7, in <module> …Run Code Online (Sandbox Code Playgroud) 我试图使用img标签加载我的svg文件,但它不能在Firefox上运行.Chrome显示了svg.我想这样做http://www.schepers.cc/svg/blendups/embedding.html.
这是我的代码......
<img src="http://ubuntu.digitalfront.ca/ghcorp/wp-content/uploads/2014/09/hillsdale.svg" alt="" class="img-responsive" />Run Code Online (Sandbox Code Playgroud)
在Firefox中,svg根本没有显示出来.我怎样才能解决这个问题?
我有这个代码:
>>> import datetime
>>> l = '2011-12-02'
>>> t = datetime.datetime.strptime(l, '%Y-%m-%d')
>>> print t
2011-12-02 00:00:00
Run Code Online (Sandbox Code Playgroud)
我的问题是,有可能只会2011-12-02打印出来吗?
我有一个使用python的项目,我想将PHP转换为python.我在PHP的数组中混淆了将它转换为python ...
在PHP的旧代码中...它看起来像这样,
array(
"Code" => 122,
"Reference" => 1311,
"Type" => 'NT',
"Amount" => 100.00
);
Run Code Online (Sandbox Code Playgroud)
这就是我将它转换为python所做的...
dict = {
"Code":122,
"Reference":1311,
"Type":'NT',
"Amount":100.00
}
Run Code Online (Sandbox Code Playgroud)
是我的转换PHP到python是正确的?
我有一个字符串,我想循环它,以便我可以检查每个字符是否是一个字母或数字.
$s = "rfewr545 345b";
for ($i=1; $i<=strlen($s); $i++){
if ($a[$i-1] == is a letter){
echo $a[$i-1]." is a letter";
} else {
echo $a[$i-1]." is a number";
}
}
Run Code Online (Sandbox Code Playgroud)
如何检查字母是字母还是数字?
我正在使用flexslider http://www.woothemes.com/flexslider/,现在我想得到幻灯片的总数和sildes的数量.
number of the slide/total number of the slides
Run Code Online (Sandbox Code Playgroud)
例如,如果我有5张幻灯片,而我现在处于第二张幻灯片中,那么这将是幻灯片下方的输出.
2/5
Run Code Online (Sandbox Code Playgroud)
如果我点击"下一个导航"它将成为
3/5
Run Code Online (Sandbox Code Playgroud)
如果"prev nav";
2/5
Run Code Online (Sandbox Code Playgroud)
flexslider有可能吗?如果有,该怎么办?
我怎么可以设置的号码admin.Tabularline中django admin?默认情况下,它显示3个空行,我只想显示1个空行.
class ClientPaymentOptionInline(admin.TabularInline):
model = ClientPaymentOption
fields = ('name', 'action','percent', 'fixamount', 'itemcharged', 'client')
class ClientAdmin(admin.ModelAdmin):
#display list
list_display = ('name','b_type','banner','logo',
'contact','address','account_type',
'status','currency','color','user',
)
#display fields
fields = ('name','b_type','banner','logo','contact',
'address','account_type','status',
'currency','color','user',
)
inlines = [ClientPaymentOptionInline]
admin.site.register(Client, ClientAdmin)
Run Code Online (Sandbox Code Playgroud)