How to assign a value to a django form field in the template?

I was wondering how you can assign a value to a django form field in the template. I know that there is other ways to assign an initial value in django, but I need to assign the value in the template because the variable is only present in the template. The way to do this with a normal html form would be this: {% for thing in things %} <p> {{ thing.content }} </p> <!-- Rep

如何为模板中的django表单字段赋值?

我想知道如何将值分配给模板中的django表单字段。 我知道在Django中还有其他方法可以分配初始值,但我需要在模板中分配值,因为变量只存在于模板中。 使用正常的html表单来做到这一点的方法是: {% for thing in things %} <p> {{ thing.content }} </p> <!-- Reply form --> <form> <input type="hidden" name="replyingto" value="{{ thing.number }}"> <input type="text

Ipython notebook 3 disables seaborn settings

I just upgraded to IPython Notebook version 3.0 and it's disabling the formatting for seaborn. Here's some sample code that replicates the problem import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline data = np.random.randn(100) fig,ax = plt.subplots(figsize = (11,8.5)) ax.plot(data) This code works just fine in IPython

Ipython笔记本3禁用seaborn设置

我刚刚升级到IPython Notebook 3.0版,并且禁用了seaborn的格式。 以下是一些复制问题的示例代码 import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline data = np.random.randn(100) fig,ax = plt.subplots(figsize = (11,8.5)) ax.plot(data) 此代码在IPython Notebook V2.4.1中运行良好(请参阅http://nbviewer.ipython.org/gist/anonymous/71733c24

Converting unix timestamp string to readable date

I have a string representing a unix timestamp (ie "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime , I get a TypeError : >>>import time >>>print time.strftime("%B %d %Y", "1284101485") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument must be 9-item sequence, n

将unix时间戳字符串转换为可读的日期

我有一个字符串表示Python中的unix时间戳(即“1284101485”),我想将其转换为可读的日期。 当我使用time.strftime ,我得到一个TypeError : >>>import time >>>print time.strftime("%B %d %Y", "1284101485") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument must be 9-item sequence, not str 使用datetime模块: import datetime print(

How do I convert datetime to date (in Python)?

如何将datetime.datetime对象(例如, datetime.datetime.now())的返回值datetime.datetime.now())转换为Python中的datetime.date对象? 使用date()方法: datetime.datetime.now().date() From the documentation: datetime.datetime.date() Return date object with same year, month and day. You use the datetime.datetime.date() method: datetime.datetime.now().date() Obviously, the expression above can (and

如何将日期时间转换为日期(使用Python)?

如何将datetime.datetime对象(例如, datetime.datetime.now())的返回值datetime.datetime.now())转换为Python中的datetime.date对象? 使用date()方法: datetime.datetime.now().date() 从文档: datetime.datetime.date() 具有相同年份,月份和日期的返回日期对象。 您使用datetime.datetime.date()方法: datetime.datetime.now().date() 显然,上面的表达式可以(也应该是恕我直言)写成: datetime.date.today()

Convert date to datetime in Python

Silly question, but is there a built-in method for converting a date to a datetime in Python, ie. getting the datetime for the midnight of the date ? The opposite conversion is easy - datetime has a .date() method. Do I really have to manually call datetime(d.year, d.month, d.day) ? You can use datetime.combine(date, time); for the time, you create a datetime.time object initialized to midn

在Python中将日期转换为日期时间

愚蠢的问题,但有一个转换内置方法date的datetime在Python,即。 获取datetime的午夜date ? 相反的转换很简单 - datetime有一个.date()方法。 我真的必须手动调用datetime(d.year, d.month, d.day)吗? 你可以使用datetime.combine(日期,时间); 暂时,您创建一个初始化为午夜的datetime.time对象。 from datetime import date from datetime import datetime d = date.today() datetime.combine(d, datetime.min.time(

Converting integer to string in Python?

I want to convert an integer to a string in Python. I am typecasting it in vain: t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j When I try to convert it to string, it's showing an error like int doesn't have any attribute called str . >>> str(

在Python中将整数转换为字符串?

我想在Python中将整数转换为字符串。 我徒劳地形容它: t=raw_input() c=[] for j in range(0,int(t)): n=raw_input() a=[] a,b= (int(i) for i in n.split(' ')) d=pow(a,b) d.str() c.append(d[0]) for j in c: print j 当我尝试将其转换为字符串时,它显示一个错误,如int没有任何称为str属性。 >>> str(10) '10' >>> int('10') 10 文档链接: int() str() 问题似

Is there a Python equivalent to C#'s DateTime.TryParse()?

Is there an equivalent to C#'s DateTime.TryParse() in Python? Edit: I'm referring to the fact that it avoids throwing an exception, not the fact that it guesses the format. If you don't want the exception, catch the exception. try: d = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") except ValueError: d = None In the zen of python, explicit is better than implicit.

有没有一个相当于C#的DateTime.TryParse()的Python?

在Python中是否有与C#的DateTime.TryParse()等价的东西? 编辑: 我指的是它避免抛出异常,而不是猜测格式。 如果你不想要这个异常,赶上例外。 try: d = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") except ValueError: d = None 在Python的禅宗中,显式比隐式更好。 strptime 总是返回以指定的确切格式解析的日期时间。 这是有道理的,因为你必须定义失败时的行为,也许你真正想要的是。 except V

How do I remove packages installed with Python's easy

Python's easy_install makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages. What is the best way of finding out what's installed, and what is the preferred way of removing installed packages? Are there any files that need to be updated if I

如何删除使用Python easy安装的软件包

Python的easy_install使安装新软件包非常方便。 但是,据我所知,它不实现依赖管理器的其他常见功能 - 列出和删除已安装的软件包。 找出安装的最佳方式是什么,以及删除安装的软件包的首选方式是什么? 如果我手动删除软件包(例如,通过rm /usr/local/lib/python2.6/dist-packages/my_installed_pkg.egg或类似软件),是否有任何需要更新的文件? pip是setuptools / easy_install的替代品,它提供了一个“卸载”命令。 根

Acquiring basic skills working with visualizing/analyzing large data sets

I'm looking for a way to learn to be comfortable with large data sets. I'm a university student, so everything I do is of "nice" size and complexity. Working on a research project with a professor this semester, and I've had to visualize relationships between a somewhat large (in my experience) data set. It was a 15 MB CSV file. I wrote most of my data wrangling in Pyth

掌握可视化/分析大型数据集的基本技能

我正在寻找一种学习适应大型数据集的方法。 我是一名大学生,所以我所做的一切都是“好”的大小和复杂性。 在这个学期和一位教授一起研究一个研究项目,我不得不想像一个有点大(以我的经验)数据集之间的关系。 这是一个15 MB的CSV文件。 我用Python编写了大部分数据,使用GNUPlot可视化。 有没有关于此主题的无障碍书籍或网站? 使用Python的奖励点数,比依赖gnuplot更多的“基本”可视化系统奖励点数。 开罗什么的,我想

Concatenate item in list to strings

Is there a simpler way to concatenate string items in list into a single string? Can I use the str.join() function to join items in list? Eg this is the input ['this','is','a','sentence'] and this is the desired output this-is-a-sentence sentence = ['this','is','a','sentence'] sent_str = "" for i in sentence: sent_str += str(i) + "-" sent_str = sent_str[:-

将列表中的项目连接到字符串

有一种更简单的方法来将列表中的字符串项连接成单个字符串吗? 我可以使用str.join()函数来加入列表中的项目吗? 例如,这是输入['this','is','a','sentence'] ,这是所需的输出this-is-a-sentence sentence = ['this','is','a','sentence'] sent_str = "" for i in sentence: sent_str += str(i) + "-" sent_str = sent_str[:-1] print sent_str 使用join : >>> sentence =