我在Linux上用C编写一个简单的Web服务器.
我必须添加一个文件的最后修改时间,该文件将被传输到客户端(浏览器),
我分析了一些网站的情况并发现它们都以格式呈现时间:
Fri, 12 Nov 2010 16:02:54 GMT,
我的问题是,我可以简单地将time_t值转换为前一种格式的字符串吗?有这个功能吗?或者格式是不重要的?
我使用SocketServer编写了一个简单的python脚本,它在Windows上运行良好,但是当我在远程Linux机器(Ubuntu)上执行它时,它根本不起作用.脚本如下所示:
#-*-coding:utf-8-*-
import SocketServer
class MyHandler(SocketServer.BaseRequestHandler):
def handle(self):
data_rcv = self.request.recv(1024).strip()
print data_rcv
myServer = SocketServer.ThreadingTCPServer(('127.0.0.1', 7777), MyHandler)
myServer.serve_forever()
Run Code Online (Sandbox Code Playgroud)
我通过SSH将其上传到远程计算机,然后python server.py在远程计算机上运行命令,并尝试xxx.xxx.xxx.xxx:7777/test使用我的浏览器访问,但远程计算机的终端上没有打印任何内容......任何想法?
更新:问题解决了,这是一个防火墙问题,谢谢大家.
例如,我有一个文件a.js,其内容是:
Hello, ??, bye.
Run Code Online (Sandbox Code Playgroud)
其中包含两个汉字,其unicode形式是\u4f60\u597d
我想写一个python程序,它将a.js中的汉字转换为unicode形式,输出b.js,其内容应为:Hello, \u4f60\u597d, bye.
我的代码:
fp = open("a.js")
content = fp.read()
fp.close()
fp2 = open("b.js", "w")
result = content.decode("utf-8")
fp2.write(result)
fp2.close()
Run Code Online (Sandbox Code Playgroud)
但似乎中文字符仍然是一个字符,而不是我想要的ASCII字符串.
我想扩展django的auth.User,看完这个问题之后,
这是我的models.py:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User)
age = models.SmallIntegerField()
def create_user_profile(sender, instance, created, **kwargs):
if created:
profile, created = UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User)
Run Code Online (Sandbox Code Playgroud)
我在settings.py的底部添加了这一行:
AUTH_PROFILE_MODULE = 'MYAPP.UserProfile'
Run Code Online (Sandbox Code Playgroud)
问题是,当我运行时python manage.py shell,键入:
from django.contrib.auth.models import User
user = User()
Run Code Online (Sandbox Code Playgroud)
它没有问题!为什么不给出我没有给出的错误username/password?
我想实现这个:
//foo is a boolean
if(foo){
count++;
} else {
count--;
}
Run Code Online (Sandbox Code Playgroud)
我怎么能用一个班轮写这个?
例如,我有一个清单a = ['3*4', '2*3', '4*6'],
我想打印列表中的字符串,其结果将是最大的,在这种情况下为"4*6".
例如,我有一个功能:
def foo(a, b, c):
pass
Run Code Online (Sandbox Code Playgroud)
现在我有一个词典:
d = {'a': 1, 'b': 2, 'c': 3}
我必须写一些类似的东西:
foo(d['a'], d['b'], d['c'])
我想知道,我可以将一些参数(如d)传递给函数吗?
我可以更改值input.value吗?
例如:
<input type="text" value="a" id="i" />
var input = document.getElementById("i");
input.value; // I want this to return double of input.value, that is "aa" in this case.
Run Code Online (Sandbox Code Playgroud)
可能吗?
我有一个清单:
nums = [1, 2, 3, 4]
Run Code Online (Sandbox Code Playgroud)
我想获得分割列表的所有可能性1 - 3:
[
( 1, (2, 3, 4) ),
( 2, (1, 3, 4) ),
( 3, (1, 2, 4) ),
( 4, (1, 2 ,3) )
]
Run Code Online (Sandbox Code Playgroud)
现在我能找到的最好的就是使用itertools.combinations(num, 3),但它只会给出每个项目的第二部分,这意味着[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)].我可以使用其他方法吗?
我想循环一个大的二维列表:
authors = [["Bob", "Lisa"], ["Alice", "Bob"], ["Molly", "Jim"], ... ]
Run Code Online (Sandbox Code Playgroud)
并获取一个列表,其中包含作者中出现的所有名称.
当我遍历列表时,我需要一个容器来存储我已经看过的名字,我想知道我是否应该使用列表或字典:
列表:
seen = []
for author_list in authors:
for author in author_list:
if not author in seen:
seen.append(author)
result = seen
Run Code Online (Sandbox Code Playgroud)
用词典:
seen = {}
for author_list in authors:
for author in author_list:
if not author in seen:
seen[author] = True
result = seen.keys()
Run Code Online (Sandbox Code Playgroud)
哪一个更快?还是有更好的解决方案?
python ×7
javascript ×2
c ×1
django ×1
dom ×1
encode ×1
gmt ×1
html ×1
linux ×1
loops ×1
performance ×1
python-2.7 ×1
sockets ×1
string ×1
unicode ×1