concatenation

Concatenation Operator + or ,

痴心易碎 提交于 2019-12-03 09:24:51
问题 var1 = 'abc' var2 = 'xyz' print('literal' + var1 + var2) # literalabcxyz print('literal', var1, var2) # literal abc xyz ... except for automatic spaces with ',' whats the difference between the two? Which to use normally, also which is the fastest? Thanks 回答1: (You're using Python 3.x, where print is a function—in 2.x, print is a statement. It's a good idea to mention the major Python version—2.x or 3.x—especially when asking for help, because currently most people reasonably assume 2.x

Casting an int to a string in Python

☆樱花仙子☆ 提交于 2019-12-03 09:18:47
I want to be able to generate a number of text files with the names fileX.txt where X is some integer: for i in range(key): filename = "ME" + i + ".txt" //Error here! Can't concat a string and int filenum = filename filenum = open(filename , 'w') Does anyone else know how to do the filename = "ME" + i part so I get a list of files with the names: "ME0.txt" , "ME1.txt" , "ME2.txt" , and etc Florian Mayer x = 1 y = "foo" + str(x) Please see the Python documentation: https://docs.python.org/2/library/functions.html#str For Python versions prior to 2.6, use the string formatting operator % :

Preserving Column Order - Python Pandas and Column Concat

旧巷老猫 提交于 2019-12-03 07:30:04
问题 So my google-fu doesn't seem to be doing me justice with what seems like should be a trivial procedure. In Pandas for Python I have 2 datasets, I want to merge them. This works fine using .concat. The issue is, .concat reorders my columns. From a data retrieval point of view, this is trivial. From a "I just want to open the file and quickly see the most important column" point of view, this is annoying. File1.csv Name Username Alias1 Tom Tomfoolery TJZ Meryl MsMeryl Mer Timmy Midsize Yoda

How do I concatenate a boolean to a string in Python?

試著忘記壹切 提交于 2019-12-03 06:27:29
问题 I want to accomplish the following answer = True myvar = "the answer is " + answer and have myvar's value be "the answer is True". I'm pretty sure you can do this in Java. 回答1: answer = True myvar = "the answer is " + str(answer) Python does not do implicit casting, as implicit casting can mask critical logic errors. Just cast answer to a string itself to get its string representation ("True"), or use string formatting like so: myvar = "the answer is %s" % answer Note that answer must be set

Concatenate XML without type casting to string

爱⌒轻易说出口 提交于 2019-12-03 06:08:26
I have the following XML generated from various tables in my SQL SERVER database <XMLData> ... <Type>1</Type> ... </XMLData> AND <XMLData> ... <Type>2</Type> ... </XMLData> AND <XMLData> ... <Type>3</Type> ... </XMLData> The final output I need is single combined as follows: <AllMyData> <XMLData> ... <Type>1</Type> ... </XMLData> <XMLData> ... <Type>2</Type> ... </XMLData> <XMLData> ... <Type>3</Type> ... </XMLData> <AllMyData> NOTE - all the independent elements that I am combining have the same tag name. Thanks in advance for looking this up. I have the following XML generated from various

Concatenate files with npm as build tool

故事扮演 提交于 2019-12-03 06:01:20
I recently discovered that I can use npm as a task runner instead of gulp or grunt, everything is fantastic so far (lint, stylus, jade, uglify, watch .. etc) but the concatenation part, I cannot seem to achieve that. With gulp it was something like: gulp.task('scripts', function() { return gulp.src('www/js/**/*.js') .pipe(concat('all.js')) .pipe(gulp.dest('www/dist')) .pipe(rename('all.min.js')) .pipe(uglify()) .pipe(gulp.dest('www/dist')); }); Is there a way I can do that with npm? To be more clear, my goal is to do something like this: // package.json { "name": "f_todo", "version": "1.0.0",

Concatenate two Func delegates

馋奶兔 提交于 2019-12-03 05:48:05
Assume that I have thes Class: public class Order { int OrderId {get; set;} string CustomerName {get; set;} } I declare below variables, too Func<Order, bool> predicate1 = t=>t.OrderId == 5 ; Func<Order, bool> predicate2 = t=>t.CustomerName == "Ali"; Is there any way that concatenate these variables(with AND/OR) and put the result in 3rd variable? for example: Func<Order, bool> predicate3 = predicate1 and predicate2; or Func<Order, bool> predicate3 = predicate1 or predicate2; And: Func<Order, bool> predicate3 = order => predicate1(order) && predicate2(order); Or: Func<Order, bool> predicate3 =

How can I concatenate a vector? [duplicate]

Deadly 提交于 2019-12-03 04:46:00
问题 This question already has answers here : Concatenate a vector of strings/character (5 answers) Closed 3 years ago . I'm trying to produce a single variable which is a concatenation of two chars e.g to go from "p30s4" "p28s4" to "p30s4 p28s4". I've tried cat and paste as shown below. Both return empty variables. What am I doing wrong? > blah = c("p30s4","p28s4") > blah [1] "p30s4" "p28s4" > foo = cat(blah) p30s4 p28s4 > foo NULL > foo = paste(cat(blah)) p30s4 p28s4 > foo character(0) 回答1: Try

CONCAT'ing NULL fields

谁说我不能喝 提交于 2019-12-03 04:42:47
问题 I have a table with three fields, FirstName, LastName and Email. Here's some dummy data: FirstName | LastName | Email Adam West adam@west.com Joe Schmoe NULL Now, if I do: SELECT CONCAT(FirstName, LastName, Email) as Vitals FROM MEMBERS Vitals for Joe is null, as there is a single null field. How do you overcome this behaviour? Also, is this the default behaviour in MS SQL Server? 回答1: Try ISNULL(FirstName, '<BlankValue>') -- In SQL Server IFNULL(Firstname, '<BlankValue>') -- In MySQL So,

Concatenation of strings in Lua

隐身守侯 提交于 2019-12-03 04:04:19
问题 In many languages you can concatenate strings on variable assignment. I have a scenario, using the Lua programming language, where I need to append the output of a command to an existing variable. Is there a functional equivalent in Lua to the below examples? Examples of other languages: ===== PERL ===== $filename = "checkbook"; $filename .= ".tmp"; ================ ===== C# ===== string filename = "checkbook"; filename += ".tmp"; =============== Thank you in advance for your help. 回答1: As