English 中文(简体)
% 不适用信息
原标题:%s Not Replacing Information

I am trying to put information available on the web, and to do so I am using string formatting:

fields = """{"fname" : %s, "lname" : %s, "email" : %s, "deptid" : deptid, "active" : active, "sentient" : sentient}""", (fname, lname, email)

with various values for each of the three variables.

不管怎么说,当我试图看到田野时,它仍然显示成百分数! 我实际上如何取而代之?

最佳回答

The character you are looking for is %, not ,. as in fields = """{"fname" : %s, "lname" : %s, "email" : %s, "deptid" : deptid, "active" : active, "sentient" : sentient}""" % (fname, lname, email)

问题回答
fields = """{"fname" : %s, "lname" : %s, "email" : %s, "deptid" : deptid, "active" : active, "sentient" : sentient}""" % (fname, lname, email)

简言之,用<>%(即操作者,有条理)取代 com(构造)。

Also, I would recommend replacing your triple quotes with single quotes (although it s not wrong the way you have it. I just find it s more readable this way).

fields =  {"fname" : %s, "lname" : %s, "email" : %s, "deptid" : deptid, "active" : active, "sentient" : sentient}  % (fname, lname, email)

您根本不使用<条码>%,而是使用简单的<条码>、、构建图形。

fields = ("""{"fname" : %s, "lname" : %s, "email" : %s, "deptid" : deptid, """
          """"active" : active, "sentient" : sentient}""" % (fname, lname, email))

不管怎么说,似乎与你一样,试图产生JSON的产出。 如果是的话,请见json

您需要使用<代码>%的操作者将变数清单与指示相挂钩,例如:

"Here is my %s" % ( "string" )

你在座标和您的变数清单之间走下了一个 com子,这确实使你们受益。





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签