所以我可以从头开始len(collection)并结束collection[0].
编辑:对不起,我忘了提到我也希望能够访问循环索引.
我找到了一个有趣的应用程序.这个fb-app从任何粉丝页获得所有喜欢并按质量和国家排序!
我的问题:
第一: 获取fanpage-object无需访问令牌
https://graph.facebook.com/cocacola/
{
"about": "The Coca-Cola Facebook Page is a collection of your stories showing how people from around the world have helped make Coke into what it is today.",
"checkins": 146,
"description": "Created in 1886 in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage at Jacob's Pharmacy by mixing Coca-Cola syrup with carbonated water. \n\nCoca-Cola was patented in 1887, registered as a trademark in 1893 and by …Run Code Online (Sandbox Code Playgroud) 我正在尝试将now的日期戳转换为Unix TimeStamp,但是下面的代码似乎被点击但是然后跳转到我的应用程序的末尾,因为似乎不喜欢time.mktime部分.
from datetime import datetime
import time
now = datetime.now()
toDayDate = now.replace(hour=0, minute=0, second=0, microsecond=0)
newDate = time.mktime(datetime.strptime(toDayDate, "%Y-%m-%d %H:%M:%S").timetuple())
print(newDate)
Run Code Online (Sandbox Code Playgroud) 我尝试安装 PyLint。安装时我看到以下内容:
\n\nCollecting pylint\n Downloading pylint-1.6.5-py2.py3-none-any.whl (577kB)\n 100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 583kB 655kB/s \nCollecting six (from pylint)\n Using cached six-1.10.0-py2.py3-none-any.whl\nCollecting isort>=4.2.5 (from pylint)\n Downloading isort-4.2.5-py2.py3-none-any.whl (40kB)\n 100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 40kB 737kB/s \nCollecting mccabe (from pylint)\n Downloading mccabe-0.6.1-py2.py3-none-any.whl\nCollecting configparser; python_version == "2.7" (from pylint)\n Downloading configparser-3.5.0.tar.gz\nCollecting backports.functools-lru-cache; python_version == "2.7" (from pylint)\n Downloading backports.functools_lru_cache-1.3-py2.py3-none-any.whl\nCollecting astroid<1.5.0,>=1.4.5 (from pylint)\n Downloading astroid-1.4.9-py2.py3-none-any.whl (213kB)\n 100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 215kB 713kB/s \nCollecting lazy-object-proxy (from astroid<1.5.0,>=1.4.5->pylint)\n Downloading lazy-object-proxy-1.2.2.tar.gz\nCollecting wrapt (from astroid<1.5.0,>=1.4.5->pylint)\n Downloading wrapt-1.10.8.tar.gz\nBuilding wheels for collected packages: configparser, lazy-object-proxy, wrapt\n Running …Run Code Online (Sandbox Code Playgroud) 我有一个Django网站,它有不同的开发和生产设置(DEBUG/ SECRET_KEY等).生产为这些设置提供环境变量.在settings.py文件我想退出,如果像这样没有给出预期的设置:
if not DEBUG and SECRET_KEY == DEFAULT_SECRET_KEY:
sys.exit("SECRET_KEY must be set when DEBUG = False")
Run Code Online (Sandbox Code Playgroud)
退出这样的settings.py文件是否正确?
假设我创建了一个MyModel具有FileFieldusingCreateView和 associated的模型实例,MyModelCreateForm现在我想在不上传相同头像图像的情况下更新它:
class MyModel(models.Model):
name = models.CharField()
avatar = models.ImageField()
class MyModelCreateForm(forms.ModeForm):
class Meta:
model = MyModel
exclude = None
class MyModelCreate(CreateView):
model = MyModel
form_class = MyModelCreateForm
class MyModelCreate(UpdateView):
model = MyModel
form_class = ?
Run Code Online (Sandbox Code Playgroud)
在 CreateView 的表单上,图像是强制性的。如果我想让它在更新字段上是可选的,那么最像 Django 的方式是什么?
我是否需要为继承自MyModelCreateForm但覆盖ImageFieldrequired属性的 UpdateView 创建一个新表单?还是有更“含电池”的方式?
在Python(2.7)中,我想在文件中创建几个变量.然后在其他文件中使用这些变量.没有任何类或功能.只是从不同的文件中访问这些变量.
如何为包含变量的文件完成,这可能看起来像这样?
variables.py
a = 1
b = 2
c = 3
Run Code Online (Sandbox Code Playgroud)
然后在一个想要使用这些变量的文件中?
file1.py
print a + b
Run Code Online (Sandbox Code Playgroud) 我的文件.env文件包含5行
DB_HOST=http://localhost/
DB_DATABASE=bheng-local
DB_USERNAME=root
DB_PASSWORD=1234567890
UNIX_SOCKET=/tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud)
我想编写python来获取DB_DATABASE的值,
我想要这个bheng-local
我会用
import linecache
print linecache.getline('.env', 2)
Run Code Online (Sandbox Code Playgroud)
但是有些人可能会更改cofigs的顺序,这就是为什么行缓存不是我的选择。
我不确定如何只检查某些字符串,但要检查整行,并在后面获取值=。
我有点卡在这里:
file = open('.env', "r")
read = file.read()
my_line = ""
for line in read.splitlines():
if line == "DB_DATABASE=":
my_line = line
break
print my_line
Run Code Online (Sandbox Code Playgroud)
有人可以在这里给我一点推动力吗?
python ×8
django ×2
datetime ×1
exception ×1
facebook ×1
facebook-fql ×1
generics ×1
import ×1
installation ×1
list ×1
loops ×1
pip ×1
python-2.7 ×1
reverse ×1
time ×1