我决定和Django玩一下(因为我已经听说过很多).我正在阅读这里的教程:
http://docs.djangoproject.com/en/1.2/intro/tutorial01/#intro-tutorial01
大约在教程的一半,我被要求从命令行运行:
python manage.py syncdb
但是,我收到此错误:
C:\django-projects\mysite>python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line 257, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Python25\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:\Python25\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python25\lib\site-packages\django\core\management\commands\syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "C:\Python25\lib\site-packages\django\core\management\sql.py", line 5, …Run Code Online (Sandbox Code Playgroud) 我对本教程不太满意.它开始变得更加"抽象",我觉得我需要开始某种Haskell项目,以巩固我已经知道的东西,看看我还没有学习的东西(所以它们更具体,更少理论值).问题是,我不知道该做些什么.我看过HappStack - 看起来真棒,但看起来也有点先进.我正在浏览haskell.org上的"99 haskell问题",但是那些很无聊,当我完成它们时我无法"炫耀".并不是说我只想展示,我只想要一些我可以"使用"的东西.
试图在名为"Beginning Scala"的Apress书中运行示例代码.我甚至从他们的网站下载了代码,以确保我没有傻瓜.获取以下消息:
/root/sum.scala:19: error: missing arguments for method collect in trait Iterator;
follow this method with `_' if you want to treat it as a partially applied function
val lines = input.getLines.collect
^
one error found
Run Code Online (Sandbox Code Playgroud)
这是我使用的源代码(在Fedora 13上运行Scala版本2.8.1.final(Java HotSpot(TM)Server VM,Java 1.6.0_22)
import scala.io._
def toInt(in: String): Option[Int] =
try {
Some(Integer.parseInt(in.trim))
} catch {
case e: NumberFormatException => None
}
def sum(in: Seq[String]) = {
val ints = in.flatMap(s => toInt(s))
ints.foldLeft(0)((a, b) => a + b)
}
println("Enter some …Run Code Online (Sandbox Code Playgroud) 在Windows XP SP2上运行Python 2.5.
当我运行一个Python脚本,Zipper.py使用Windows scheduledTask 调用一个名为(基本上是zip文件的包装器)的用户定义模块时,我得到以下异常:
回溯(最近一次调用最后一次):
文件"C:\ PythonScripts\ZipAndSendEOD-Reports.py",第78行,在主
Zipper.main([report],f,debug = True)#[: - 4] +"_ "+ str(x)+".zip")
TypeError:main()得到一个意外的关键字参数'debug'
奇怪的是,如果我只是在IDLE中打开文件并点击"F5",它就会运行得很完美.
我确定我遗漏了一些相关信息,请让我知道你需要什么.
Zipper.py 看起来像这样:
import zipfile
def main(archive_list=[],zfilename='default.zip', debug=False):
if debug: print 'file to zip', zfilename
zout = zipfile.ZipFile(zfilename, "w", zipfile.ZIP_DEFLATED)
for fname in archive_list:
if debug: print "writing: ", fname
zout.write(fname)
zout.close()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
编辑:我在调用函数中添加了以下两行代码,现在可以正常工作了.
f = open(logFile, 'a')
f.write(Zipper.__file__)
Run Code Online (Sandbox Code Playgroud)
你能解释一下吗?
这可能是一个真正愚蠢的问题,但我还没有找到答案.一旦我根据需要修改了xml树,我该如何将其写回文件?
码:
workbook = open("C:\\Users\\rabdel.WINCMPT\\Documents\\Retail Footwear.twb")
soup = BeautifulSoup(workbook)
for dashboard in soup.findAll("dashboard"):
print dashboard["name"]
if dashboard["name"] == "S1":
dashboard.extract()
for window in soup.findAll("window"):
print "class:",window["class"]
if "name" in [x[0] for x in window.attrs]:
print "name:",window["name"]
if window["name"] == "S1":
window.extract()
Run Code Online (Sandbox Code Playgroud) 我需要覆盖ActionMailer的mail方法.这个方法受到保护所以在子类中,我也将mail方法定义为protected:
protected
def mail(headers={}, &block)
#add a check to avoid sending emails that end with ".old"
unless headers[:to] =~ /\.old$/
super(headers, &block)
end
end
Run Code Online (Sandbox Code Playgroud)
这样,当外发电子邮件地址结束时.old,该方法应返回nil而不发送电子邮件.
但是,在我的单元测试中,似乎还有一封电子邮件 ActionMailer::Base.deliveries
这是我的单元测试:
describe 'BaseNotifier' do
class TestNotifier < BaseNotifier
def mailer(to, from, subject)
mail(:to => to,
:from => from,
:subject => subject)
end
end
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
end
it "should not send emails to a user with an email that ends in …Run Code Online (Sandbox Code Playgroud) 我对导轨非常生疏,我认为自从我使用它以来的 7 年里发生了很多变化。
我正在尝试设置此示例应用程序:https : //iridakos.com/news/2015/06/21/rails-sample-api-ui
我面临的问题是 UI 没有正确地与 API 交互。我在下面的屏幕截图中收到错误消息。
lofocats UI 应用程序为我提供了以下堆栈跟踪:
KeyError (key not found: :ciphers):
lib/api/resource.rb:39:in `execute'
app/models/cat_entry.rb:46:in `all'
app/controllers/cat_entries_controller.rb:9:in `index'
app/controllers/application_controller.rb:44:in `set_api_authentication_token'
Run Code Online (Sandbox Code Playgroud)
application_controler.rb 中的第 44 行是 begin 块 ( Api::Configuration.current_authentication_token = session[:user_information][:authentication_token] if is_user_signed_in?)的第一行:
def set_api_authentication_token
begin
Api::Configuration.current_authentication_token = session[:user_information][:authentication_token] if is_user_signed_in?
yield
ensure
# Always nullify the token after each action.
Api::Configuration.current_authentication_token = nil
end
end
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个错误。我以前没有见过它,搜索 SO 给出了一些 Cloudinary 的具体答案。
我总共是F#n00b,所以希望我能给您足够的信息。我创建了一个称为记录的类。我使用数据库中的数据创建该类的几个实例。然后,我将每个记录添加到记录列表中。我想用这些记录制作一个xml文档。
//this is the record data type i created. I also created a sender and recipient data
//type but those are probably not neccessary to understand the issue
type record(id:int, sender:sender, ?recipients: recipient list ) =
let mutable id: int = id
let mutable typ = "Message"
let mutable creation = creation()
let mutable sender = sender
let mutable recipients = recipients
[<XmlIgnore()>]
[<XmlArrayAttribute("recipients")>]
[<XmlArrayItem(typeof<recipient>, ElementName = "recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的 python 脚本从发出 curl 命令转换os.system()为使用请求。我以为我会使用 pycurl,但这个问题让我信服。问题是我从服务器返回了一个错误,我在使用 r.text 时可以看到这个错误(来自这个答案),但我需要更多信息。有没有更好的方法来调试正在发生的事情?
我认为这个问题与将我的 --data 标志从 curl/pycurl 转换为请求有关。我已经创建了一个我之前传递给 --data 的参数的字典。我的猜测是其中之一无效,但我如何才能获得更多信息才能确定?
例子:
headers2 = {"Accept":"*/*", \
"Content-Type":"application/x-www-form-urlencoded", \
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36", \
"Origin":"https://somedomain.com", \
"X-Requested-With":"XMLHttpRequest", \
"Connection":"keep-alive", \
"Accept-Language":"en-US,en;q=0.8", \
"Referer":"https://somedomain.com/release_cr_new.html?releaseid=%s&v=2&m=a&prev_release_id=%s" % (current_release_id, previous_release_id), \
"Host":"somedomain.com", \
"Accept-Encoding":"gzip,deflate,sdch", \
"Cookie":'cookie_val'}
for bug_id in ids:
print bug_id
data = {'dump_json':'1','releaseid':current_release_id, 'v':'2','m':'a','prev_release_id': previous_release_id,'bug_ids': bug_id, 'set_cols':'sqa_status&sqa_updates%5B0%5D%5Bbugid%5D=' + bug_id + '&sqa_updates%5B0%5D%5Bsqa_status%5D=6'}
print …Run Code Online (Sandbox Code Playgroud) 所以,我在纯 sql 中按照我想要的方式工作:
select * from clients c
join insurance_providers p on c.id = p.client_id
where p.effective_on =
(select max(effective_on)
from insurance_providers group by client_id having p.client_id = client_id)
and user_id = 2; #user_id =2 where 2 represents current_user.id
Run Code Online (Sandbox Code Playgroud)
这是我在控制台中尝试过的:
Client.joins(:insurance_providers)
.select('max(insurance_providers.effective_on)')
.group(:client_id)
.where('user_id = 2')
Run Code Online (Sandbox Code Playgroud)
它立即在我的脸上爆炸:
NoMethodError:2013 年 7 月 8 日星期一的未定义方法“组”:日期
看起来我只是从 select 语句返回日期本身。我需要类似的东西"where effective_on = .select('max..."
任何帮助将不胜感激。
更新:我越来越接近这个:
InsuranceProvider.maximum(:effective_on, :group => 'client_id')
Run Code Online (Sandbox Code Playgroud)
但我不确定如何加入客户表以获取我需要的所有信息。在 rails 控制台中,这两个:
Client.joins(:insurance_providers).maximum(:effective_on, :group => 'client_id')
Client.joins(:insurance_providers.maximum(:effective_on, :group => 'client_id'))
Run Code Online (Sandbox Code Playgroud)
导致此错误:
NoMethodError:2013 年 …