我正在尝试编译一个程序(python2.7),但无论我做什么,我都会遇到这个错误:
C:/Python27/tcl/tk8.5/tk.tcl: version conflict for package "Tk": have 8.5.2, need exactly 8.5.15
version conflict for package "Tk": have 8.5.2, need exactly 8.5.15
while executing
"package require -exact Tk 8.5.15"
(file "C:/Python27/tcl/tk8.5/tk.tcl" line 18)
invoked from within
"source C:/Python27/tcl/tk8.5/tk.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $file]"
Run Code Online (Sandbox Code Playgroud)
这可能意味着tk安装不正确.
有人可以向我解释一下这里有什么问题吗?
我正在使用数据库路由器,因此我的应用程序有两个数据库.一个数据库用于默认的django数据,另一个数据库.
在我的管理员中,我已覆盖该save_model函数以保存created_by变量,但我无法执行此操作.
Cannot assign "<User: testuser>": the current database router prevents this relation.
Run Code Online (Sandbox Code Playgroud)
数据库路由:
from django.conf import settings
class DatabaseAppsRouter(object):
def db_for_read(self, model, **hints):
"""Point all read operations to the specific database."""
if settings.DATABASE_APPS_MAPPING.has_key(model._meta.app_label):
return settings.DATABASE_APPS_MAPPING[model._meta.app_label]
return None
def db_for_write(self, model, **hints):
"""Point all write operations to the specific database."""
if settings.DATABASE_APPS_MAPPING.has_key(model._meta.app_label):
return settings.DATABASE_APPS_MAPPING[model._meta.app_label]
return None
def allow_relation(self, obj1, obj2, **hints):
"""Allow any relation between apps that use the same database."""
db_obj1 = settings.DATABASE_APPS_MAPPING.get(obj1._meta.app_label)
db_obj2 = …Run Code Online (Sandbox Code Playgroud) 到目前为止,我还没有找到任何解决如何格式化负货币的问题,这让我发疯。
from decimal import *
import re
import sys
import os
import locale
locale.setlocale( locale.LC_ALL, 'English_United States.1252' )
# cBalance is a running balance of type Decimal
fBalance = locale.currency( cBalance, grouping=True )
print cBalance, fBalance
Run Code Online (Sandbox Code Playgroud)
负数结果:
-496.06 ($496.06)
Run Code Online (Sandbox Code Playgroud)
我需要一个减号而不是括号
如何去掉括号并得到减号?
在我的CSS中,我改变了滚动条的样式,它看起来像
body::-webkit-scrollbar {
width: 0.7em;
}
body::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(154,165,159,0.5);
}
body::-webkit-scrollbar-thumb {
background-color: #D0CACD;
outline: 1px solid LightGrey;
box-shadow: 7px 7px 50px grey;
}
Run Code Online (Sandbox Code Playgroud)
有用.如果我添加悬停:
body::-webkit-scrollbar-thumb:hover {
background-color: #b8c0bc;
}
Run Code Online (Sandbox Code Playgroud)
然后它也适用于我添加webkit动画,然后为什么它不起作用.添加webkit动画后,它看起来像:
body::-webkit-scrollbar-thumb:hover {
background-color: #b8c0bc;
-webkit-animation: scrollbig 1s;
animation: scrollbig 2s;
}
Run Code Online (Sandbox Code Playgroud)
动画无法播放.为什么?我正在使用谷歌浏览器.你还可以看到@keyframe动画代码:
@-webkit-keyframes scrollbig {
from {width: 0.6em;}
to {width: 0.9em;}
}
Run Code Online (Sandbox Code Playgroud)
请告诉我们如何制作动画.特别感谢.
所以我陷入了一个我正在研究的涉及python命令行的项目.
基本上,这就是我想要完成的事情:
我在课堂上有一套功能,比方说,
def do_option1(self, param1, param2) :
#some python code here
def do_option2(self, param1):
#some python code here
def do_option3(self, param1, param2, param3):
#some python code here
Run Code Online (Sandbox Code Playgroud)
基本上,当用户filename.py option2 param1进入命令行时,我希望它调用该函数do_option2并将参数传递param1给它.
类似地,当用户放置时filename.py option3 param1 param2 param3,我希望它使用给定的参数执行do_option3函数.
我知道有2个模块的蟒蛇叫argparse和optparse,但我已经很难理解这两个,我不知道,如果单独两个会完成我需要做.
python command-line optparse command-line-arguments argparse
我已经找到了一种方法让代码按照我的意愿运行,但我想了解为什么它的行为如此,以便我对Go并发性的理解得到改善.
我正在测试sync.WaitGroup等待一些goroutines完成,因为我计划以这种方式多次上传到Amazon S3.
这是我原来的代码:
func main() {
var wg sync.WaitGroup
for i := 1; i <= 5; i++ {
wg.Add(1)
go func() {
fmt.Println(i)
time.Sleep(time.Second * 1)
wg.Done()
}()
}
wg.Wait()
}
Run Code Online (Sandbox Code Playgroud)
我惊讶地看到输出是:6, 6, 6, 6, 6.
而不是像:2, 4, 1, 5, 3.
由于循环甚至没有达到6,这对我来说没有任何意义.我后来将i变量作为参数传递给匿名函数,然后它表现得像我预期的那样.
为什么会这样?我不明白.
我正在尝试运行pip install zbar,由于某种原因,我似乎无法找到解决此依赖性问题的答案.任何帮助将非常感激.见下面的追溯:
Downloading/unpacking zbar
Downloading zbar-0.10.tar.bz2
Running setup.py
egg_info for package zbar
Installing collected packages: zbar
Running setup.py install for zbar
building 'zbar' extension
clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c zbarmodule.c -o build/temp.macosx-10.9-x86_64-2.7/zbarmodule.o
In file included from zbarmodule.c:24:
./zbarmodule.h:26:10: fatal error: 'zbar.h' file not found
#include <zbar.h>
^
1 error generated.
error: command 'clang' failed with exit status 1
running install
running build
running build_ext
building 'zbar' extension
creating …Run Code Online (Sandbox Code Playgroud) 我已经设置了我的配置,以便远程运行服务器.当我单击运行时,我看到使用的命令:
ssh://vagrant@localhost:2222/usr/bin/python -u "C:/Users/MyName/ProjectName/config/manage.py" runserver localhost:8080
Run Code Online (Sandbox Code Playgroud)
(由于匿名原因,我已经替换了目录名称).
当我运行它时,它失败(显然)因为它使用了我的manage.py的Windows路径特别是我得到的错误是
`/usr/bin/python: can't open file 'C:/Users/MyName/judgeapps/config/manage.py': [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
在广泛的谷歌搜索之后我无法弄清楚的是如何强制django在我的流浪汉机器上使用路径.我该怎么做呢?
由于某种原因,当该字段未更改时,Django 要求我随机迁移。迁移文件是相同的。
模型:
PROGRESS_CHOICE = {
('1', '1.start'),
('2', '2.driver_arrived_pick_up'),
('3', '3.hope_in'),
('4', '4.driver_arrived_destination'),
('5', '5.end')
}
progress = models.CharField(max_length=20, choices=PROGRESS_CHOICE, default=1, blank=True)
Run Code Online (Sandbox Code Playgroud)
迁移:1。
class Migration(migrations.Migration):
dependencies = [
('api', '0031_auto_20150603_1515'),
]
operations = [
migrations.AlterField(
model_name='ride',
name='progress',
field=models.CharField(max_length=20, default=1, blank=True, choices=[('1', '1.start'), ('3', '3.hope_in'), ('4', '4.driver_arrived_destination'), ('2', '2.driver_arrived_pick_up'), ('5', '5.end')]),
preserve_default=True,
),
]
Run Code Online (Sandbox Code Playgroud)
2.
class Migration(migrations.Migration):
dependencies = [
('api', '0032_auto_20150603_1734'),
]
operations = [
migrations.AlterField(
model_name='ride',
name='progress',
field=models.CharField(default=1, max_length=20, choices=[('1', '1.start'), ('4', '4.driver_arrived_destination'), ('5', '5.end'), ('3', '3.hope_in'), ('2', …Run Code Online (Sandbox Code Playgroud) 我已经查看了各种链接,但所有链接都展示了如何一次性替换多个单词。然而,我想替换的不是单词而是模式,例如
RT @amrightnow:“真正的特朗普”关于你的特朗普”观看制作#1 https:\/\/t.co\/j58e8aacrE #tcot #pjnet #1A #2A #Tru mp #trump2016 https:\/\/t。合作\u2026
当我对上面的文本执行以下两个命令时,我得到了所需的输出
result = re.sub(r"http\S+","",sent)
result1 = re.sub(r"@\S+","",result)
Run Code Online (Sandbox Code Playgroud)
这样我就删除了所有的 url 和 @(推文中的处理程序)。输出将类似于以下内容:
>>> result1
'RT "The Real Trump" Trump About You" Watch Make #1 #tcot #pjnet #1A #2A #Trump #trump2016 '
Run Code Online (Sandbox Code Playgroud)
有人可以让我知道最好的方法是什么吗?我基本上会从文件中读取推文。我想阅读每条推文并将这些处理程序和网址替换为空白。
python ×6
django ×4
argparse ×1
c++ ×1
command-line ×1
css ×1
css3 ×1
currency ×1
django-admin ×1
django-forms ×1
formatting ×1
go ×1
html ×1
optparse ×1
pycharm ×1
python-2.7 ×1
regex ×1
tcl ×1
twitter ×1
vagrant ×1