我有一个different_classes包含三个不同类的文件.它是这样的:
class first(object):
def __init__(x, y, z):
body of the first class
class second(first):
def __init__(x, y, z, a=2, b=3):
body of the second class
class third(object):
def __init__(x, y, z):
body of the third class
Run Code Online (Sandbox Code Playgroud)
现在我有另一个文件,说main.py我希望能够传递需要调用的类的名称.例如,我现在做:
import different_classes
def create_blah():
instance = different_classes.first()
rest of the function body
Run Code Online (Sandbox Code Playgroud)
当我想要使用第一堂课的时候different_classes.如果我想使用类second,我使用different_classes.second().
我可以在create_blah函数中输入类名作为参数.就像是:
def create_blah(class_type = "first", x=x1, y=y1, z=z1):
instance = different_classes.class_type(x, y, z)
Run Code Online (Sandbox Code Playgroud)
我知道这可能无效......但想知道是否可以做类似的事情.谢谢!
我的meteor.js应用程序崩溃了.我收到以下错误.看来该错误不在我的应用程序代码中.如果有人可以查看以下消息并让我知道如何摆脱这个错误,我将不胜感激.
错误信息
Your application is crashing. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:
Exception while bundling application:
Error: EACCES, permission denied '/Users/username/Dropbox/LearnSoftware_and_Math/LearnJavascript/LearnMeteor/microscope/.meteor/local/build/app/collections/posts.js'
at Object.fs.unlinkSync (fs.js:582:18)
at Object._.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:278:10)
at _.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:274:15)
at Array.forEach (native)
at Function._.each._.forEach (/Users/username/.meteor/tools/275efdf2db/lib/node_modules/underscore/underscore.js:79:11)
at Object._.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:272:9)
at _.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:274:15)
at Array.forEach (native)
at Function._.each._.forEach (/Users/username/.meteor/tools/275efdf2db/lib/node_modules/underscore/underscore.js:79:11)
at Object._.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:272:9)
at _.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:274:15)
at Array.forEach (native)
at Function._.each._.forEach (/Users/username/.meteor/tools/275efdf2db/lib/node_modules/underscore/underscore.js:79:11)
at Object._.extend.rm_recursive (/Users/username/.meteor/tools/275efdf2db/tools/files.js:272:9)
at _.extend.write_to_directory (/Users/username/.meteor/tools/275efdf2db/tools/bundler.js:794:11)
at Object.exports.bundle (/Users/username/.meteor/tools/275efdf2db/tools/bundler.js:873:12)
at /Users/username/.meteor/tools/275efdf2db/tools/run.js:694:26
at exports.inFiber (/Users/username/.meteor/tools/275efdf2db/tools/fiber-helpers.js:24:12) …Run Code Online (Sandbox Code Playgroud) 我正在使用coffeescript.我在网上看到,当使用coffeescript和Meteor时,应该使用@来定义全局变量,例如集合.我已经这样做但我仍然收到以下错误.错误后会显示相关文件中的代码.我该如何解决这个错误?
谢谢.
错误--------
ReferenceError: GameStatus is not defined
at app/server/methods/adminMethods.coffee.js:10:5
Run Code Online (Sandbox Code Playgroud)
---------------------------------- collections/gamestatus.coffee ----------- -----------------------
@GameStatus = new Meteor.Collection('gamestatus')
Run Code Online (Sandbox Code Playgroud)
---------------------------------- server/adminMethods.coffee ----------- -----------------------
Meteor.methods
initializeGameStatus: () ->
GameStatus.insert({gameOnOff: 0, asymmetric: 0})
if GameStatus.find({}).count() is 0
Meteor.call 'initializeGameStatus', (err, result) ->
if err
console.log(err)
else
'GameStatus collection initialized'
Run Code Online (Sandbox Code Playgroud) 在下面的代码中row是一个由200个元素(数字)组成listOfVars的元组,是一个200个字符串的元组,它们是变量名testTable.tupleForm是一个元组列表,每个元组中有200个元素.
以下代码不起作用.它返回语法错误:
for row in tupleForm:
cmd = '''INSERT INTO testTable listOfVars values row'''
cur.execute(cmd)
Run Code Online (Sandbox Code Playgroud)
但是,以下工作正常.有人可以解释原因吗?我发现sqlite非常直观.
for row in tupleForm:
cmd = '''INSERT INTO testTable %s values %s'''%(listOfVars, row)
cur.execute(cmd)
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我有文字显示学生所选课程的课程编号,姓名,成绩和其他信息.具体来说,线条看起来像这样:
0301 453 20071 LINEAR SYSTEMS I A 4 4 16.0
0301 481 20071 ELECTRONICS I WITH LAB A 4 4 16.0
0301 481 20084 ELECTRONICS II WITH LAB RE B 4 4 12.0
0301 713 20091 SOLID STATE PHYSICS NG 0 0 0.0
0511 454 20074 INT'L TRADE & FINANCE B 4 4 12.0
Run Code Online (Sandbox Code Playgroud)
我想写一个正则表达式,提取:
LINEAR SYSTEMS I
ELECTRONICS I WITH LAB
ELECTRONICS II WITH LAB
SOLID STATE PHYSICS
INT'L TRADE & FINANCE
Run Code Online (Sandbox Code Playgroud)
我写了以下内容
pattCourseName = re.compile(r'([-/&A-Z\':\s]{2,})(\s+[A-Z])')
但是,这给了我
LINEAR …Run Code Online (Sandbox Code Playgroud) 我试图了解标志的n字符串格式中的选项值究竟是什么type.
PEP 3101说(在可用的整数类型部分):
'n' - Number. This is the same as 'd', except that it uses the
current locale setting to insert the appropriate
number separator characters.
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码:
print "This is a large number with formatting applied: {0:n}".format(1384309238430)
Run Code Online (Sandbox Code Playgroud)
我得到输出:
This is a large number with formatting applied: 1384309238430
Run Code Online (Sandbox Code Playgroud)
也就是说,不存在数字分隔符.如何找到我的区域设置?如何获取数字分隔符(我认为通过数字分隔符,它指的是诸如千位分隔符逗号之类的东西).
我无法弄清楚为什么以下功能不起作用.如有必要,我将为该示例创建数据.请告诉我.但这需要花费很多时间,因此,我想首先询问没有数据的情况,万一,问题很明显,你可以看到没有数据.
请参阅下面的代码.如果我使用该功能
plotReturns(8, "1930-01-01", "1940-12-31", "savehere.pdf")
文件savehere.pdf已创建,但我无法打开它.我收到一个错误说
打开此文档时出错.无法打开此文件,因为它没有页面.
但是,如果不是使用该函数,我手动遍历该函数代码中的每一步(用上面作为参数使用的值替换变量名)然后文件savehere.pdf被创建好我可以打开它.
所以,看来我的任何特定命令都没有错.但是,为什么函数在被称为函数时不起作用?
谢谢你的帮助.
plotReturns = function(decileValue, startDate, endDate, fileName) {
# Keep data from specific decile
specificdecile <- merged.data[merged.data$decile_correct == decileValue,]
#filter the data to get rows within the specified dates
specificdecileAndYears <- specificdecile[
((specificdecile$rdate >= as.Date(startDate)) &
(specificdecile$rdate <= as.Date(endDate))),]
#keep the necessary columns:rdate, decile_correct, vwret_bottomup, vwret_CRSP
specificdecileAndYears <- specificdecileAndYears[c("rdate", "decile_correct",
"vwret_bottomup", "vwret_CRSP")]
# Melt the data for plotting
melted.data <- melt(specificdecileAndYears, id=c("rdate","decile_correct"))
# Use melted data …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
var myRootRef = new Firebase('https://myacct.firebaseIO.com');
var collectionRef = myRootRef.child('collection');
var pushRef = collectionRef.push();
pushRef.set('item1');
pushRef.set('item2');
pushRef.set('item3');
Run Code Online (Sandbox Code Playgroud)
如果我转到网址:'https://myacct.firebaseIO.com',我只会在集合中看到'item3'.我没有看到其他两个.似乎正在重写集合对象而不是将其添加到.如果我手动输入子名称,就可以了.例如,以下工作:
collectionRef.child(1).set('item1');
collectionRef.child(2).set('item2');
collectionRef.child(3).set('item3');
Run Code Online (Sandbox Code Playgroud)
这是一个错误,还是我在使用的方式上做错了push什么?
谢谢.
在 ably.io 上,他们有一个示例,可以使用以下 curl 请求将消息发布到频道:
curl -X POST https://rest.ably.io/channels/channelname/messages \
-u "some_AP.aYYMcQ:VmGHauKOqo-35Zxo" \
-H "Content-Type: application/json" \
--data '{ "name": "greeting", "data": "example" }'
Run Code Online (Sandbox Code Playgroud)
传递给 -u 的值是具有发布权限的 API 密钥。如何使用 Python requests 库发出相同的 post 请求?我搜索了文档,但找不到。注意这里没有密码,只有api密钥。
提前致谢。
我正在尝试学习如何使用numpy的结构化数组.具体来说,我试图一次向多个字段添加信息.我试过了:
import numpy as np
numrec = np.zeros(8, dtype=[('col0', 'int16'), ('col1', 'int16'),
('col2', 'int16'), ('col3', 'int16')])
numrec[['col1','col2']][0:2] = [(3,5), (1,8)]
print numrec
Run Code Online (Sandbox Code Playgroud)
以上不起作用.这些值不会添加到指定的列中.令人惊讶的是,当我运行它时,我没有收到任何错误.有人可以解释一下发生了什么吗?
谢谢.