如何通过编辑每个链接将关注点放在我网站的每个链接的末尾?
例如 www.WebsiteName.com/?ref=123
所以如果我去了, www.WebsiteName.com/aboutus.php我希望它添加?ref=123到网址的末尾.
class cga(object):
''''''
def __int__(self,i,o):
''''''
self.i = i
self.o = o
def get(self):
''''''
self.i = []
c = raw_input("How many courses you have enrolled in this semester?:")
cout = 0
while cout < c:
n = raw_input("plz enter your course code:")
w = raw_input("plz enter your course weight:")
g = raw_input("plz enter your course grade:")
cout += 1
self.i.append([n,w,g])
if __name__ == "__main__":
test = cga()
test.get()
Run Code Online (Sandbox Code Playgroud)
我的问题是如果我输入5,当程序询问我注册了多少课程.循环不会停止,程序将继续询问输入课程代码的重量等级.我调试时显示程序有cout = 6,但是它与c进行比较而while循环不会停止.
出于某种原因,我无法在MainHandler之外实例化set_cookie ..这是一个小代码来显示我想要做什么..任何人都可以帮忙吗?
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
from GenCookie import *
class MainHandler(tornado.web.RequestHandler):
def get(self):
g=GenCookie()
response = g.genCookie()
class GenCookie:
def genCookie(self):
print self.request.remote_ip
print self.cookies
print self.request.headers
expires = datetime.datetime.utcnow() + datetime.timedelta(days=365)
if ("uid" in cookies):
self.set_cookie("uid", value=cookies["uid"],expires=expires)
else:
self.set_cookie("uid", value='dfc278623ab44df2bd501e106e81d146',expires=expires)
return
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
有人可以解释这与Python解释器的工作原理背后的逻辑吗?这种行为只是本地线程吗?为什么第二个模块导入后第一个模块导入中的赋值仍然存在?我刚刚进行了长时间的调试会议.
external_library.py
def the_best():
print "The best!"
Run Code Online (Sandbox Code Playgroud)
modify_external_library.py
import external_library
def the_best_2():
print "The best 2!"
external_library.the_best = the_best_2
Run Code Online (Sandbox Code Playgroud)
main.py
import modify_external_library
import external_library
external_library.the_best()
Run Code Online (Sandbox Code Playgroud)
测试:
$ python main.py
The best 2!
Run Code Online (Sandbox Code Playgroud) python monkeypatching side-effects global-variables python-internals
我是Python新手。我正在尝试编写一个非常基本的函数,但出现错误。我不知道其背后的原因。示例代码:
def printme( str ):
print str;
return;
printme("My string");
Run Code Online (Sandbox Code Playgroud)
这应该按逻辑执行,但它给了我以下错误:
回溯(最近一次调用):文件“stdin”,第 1 行,在“模块”中
NameError:名称“printme”未定义
欢迎任何建议...
我有一个非常复杂的jquery模板,我ViewModel通过knockout.js框架与基于javascript的数据绑定.其实,我有一个observableArray的ViewModel内的另一对象ViewModel是被绑定到我的模板.
在我的模板中,我有几个DOM元素,当它们的值发生变化时会触发某些事件.例如,我有一个单选按钮设置,当选择一个值时,它会改变选择列表的绑定(以及启用),这反过来通过改变各种可观察的属性来清除文本框的值(以及启用)在我的范围内ViewModel.这些触发器有助于为最终用户指导UX流程,并确保根据需要保存或清除某些值.这一切都很好.
然而...
当我从我的数据库中检索初始数据并填充我的ViewModels,然后将其绑定ViewModels到模板时,触发器就会响应.但是,我不希望由于触发器触发而清除基础可观察值.所以,我设计的是一种初始设置我ViewModel的IsInitialData可观察值的方法true,我的触发器用它来确定是否清除某些值.但是,我希望在false完成模板绑定之后,以及在执行任何用户交互之前将这些属性设置为.
对我来说最有意义的是使用afterRender回调来设置IsInitialData属性false.这样,我的触发器会在绑定初始数据后正常触发.我的afterRender回调函数如下所示:
function resetIsInitialDataAttribute(nodesArray, dataValue) {
alert(dataValue.IsInitialData()); // Displays 'true'
dataValue.IsInitialData(false);
alert(dataValue.IsInitialData()); // Displays 'false'
}
Run Code Online (Sandbox Code Playgroud)
有意思的是,即使设置了值,我也可以在上面的函数中读取该值.
然而...
一旦我在afterRender上面的回调函数中设置了值,我的可观察绑定似乎就会中断.为了测试,我在我的模板中放置了一个div来序列化我的observableArray所以我可以显示我ViewModel的所有值:
<div data-bind="text: ko.toJSON(locationsViewModel.locations)"></div>
Run Code Online (Sandbox Code Playgroud)
如果我没有IsInitialData在afterRender回调中设置属性,那么当我修改已绑定到我ViewModel的可观察属性的DOM元素时,上面的div会立即显示修改后的值.但是,如果我IsInitialData在回调函数中设置我的属性,上面的div不再显示我的任何更改的值ViewModel.
有谁知道为什么ViewModel在afterRender回调函数中设置我的属性会导致问题?IsInitialData …
很确定我的问题标题很糟糕,但无论如何我有一张名为发票的表,在该表内,每张发票都有一个id,每个id都有一个客户ID,所以客户会有多张发票.我试图获得最新的发票余额,我写的代码不起作用,谁能告诉我我做错了什么?
SELECT c.clientid,
c.clientname,
c.billingdate,
(SELECT remainingbalance
FROM invoice i
WHERE i.client = c.clientid) AS remaining
FROM client c
ORDER BY clientname
Run Code Online (Sandbox Code Playgroud) 我正在使用Slick.
我有两个案例类:A和B.我想结合A,并B和存储组合类到数据库中.
case class A (a: String, b: Int)
case class B (c: Double, d: Int)
//TODO class C has the property of A and B
class C(val a: A, val b: B) {}
//Now I want to create a table for C
class Tb(tag: Tag) extends Table[C](tag, "a") {
def col1 = column[String]("k1")
def col1 = column[Int]("k2")
def col1 = column[Double]("k3")
def col1 = column[Int]("k4")
def * = // …Run Code Online (Sandbox Code Playgroud) 我的标题可能没有描述我试图理解的问题代码:
这是一段代码:
def getMeConcurrentInputStream[A, I <: InputStream](in:I)(fn:I => A):Future[A] = {
future {
fn(in)
}andThen {
case all => in.close()
}
}
Run Code Online (Sandbox Code Playgroud)
我试图了解该功能的用途.这是什么:
[A, I <: InputStream](in:I)(fn:I => A)
Run Code Online (Sandbox Code Playgroud)
这是什么: (in:I)(fn:I => A)
而功能正在回归未来?我怎么解释:Future[A]
我如何解释以上所有内容?如何通过从代码中的其他位置调用它来使用此函数?
我使用BeautifulSoup替换html文件中的所有逗号‚.这是我的代码:
f = open(sys.argv[1],"r")
data = f.read()
soup = BeautifulSoup(data)
comma = re.compile(',')
for t in soup.findAll(text=comma):
t.replaceWith(t.replace(',', '‚'))
Run Code Online (Sandbox Code Playgroud)
此代码有效,除非html文件中包含一些javascript.在这种情况下,它甚至用javascript代码替换逗号(,).这不是必需的.我只想替换html文件的所有文本内容.
python ×5
scala ×2
class ×1
comparison ×1
debugging ×1
future ×1
javascript ×1
jquery ×1
knockout.js ×1
php ×1
raw-input ×1
request ×1
select ×1
setcookie ×1
side-effects ×1
slick ×1
sql ×1
tornado ×1
while-loop ×1