I've a method that I want to be able to accept either a single string (a path, but not necessarily one that exists on the machine running the code) or a ... |
Example:
regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
Why result["somekey"] tuple now not string?
|
I have a tuple of strings that i would want to extract the contents as a quoted string, i.e.
tup=('string1', 'string2', 'string3')
when i do this
main_str = ",".join(tup)
#i get
main_str = 'string1, string2, string3'
#I ...
|
I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?
|
This is what I normally do in order to ascertain that the input is a list/tuple - but not a str. Because many times I stumbled upon bugs where a function ... |
I would like to transform a tuple:
TEST_CLASSES = (
'common.test.TestClass',
)
to
TEST_CLASSES = {
'test': common.test.TestClass,
}
How to make a dictionary is simple but I have a problem with conversion ... |
I have a code:
print "bug " + data[str.find(data,'%')+2:-1]
temp = data[str.find(data,'%')+2:-1]
time.sleep(1)
print "bug tuple " + tuple(temp.split(', '))
And after this my application displays:
bug 1, 2, 3
Traceback (most recent
... |
|
I want to know that why adding a trailing comma after a string makes it tuple. I.e.
abc = 'mystring',
print abc
# ('mystring,)
When I print abc it returns a tuple like ('mystring',). ... |
I have a tuple.
tst = ([['name', u'bob-21'], ['name', u'john-28']], True)
And I want to convert it to a string..
print tst2
"([['name', u'bob-21'], ['name', u'john-28']], True)"
what is a good way to do this?
Thanks!
|
Tup = ('string1','string2','string3')
My program returned string2 how do I get it's index within Tup?
|
Yeah, I know this little problem is pretty lame, but I'm trying out Python and I figured it'd be pretty simple. I'm having a hard time figuring out how the native ... |
I have a text file i would like to read in that contains rows of tuples. Each tupel/row in text is in the form of ('description string', [list of integers ... |
Is there an easy way (hopefully a one liner) to replace '' with something like '-'?
Many thanks.
tup = (1,2,'ABC','','','','text')
|
Which of these Python string interpolations is proper (not a trick question)?
'%s' % my_string
'%s' % (my_string)
'%s' % (my_string, )
If it varies by version, please summarize.
|
I need a clean way to determine if a string is actually a tuple, like so:
'(123,456)' --> True
'hello world' --> False
I can think of two ways to do this:
- a regex
- call eval ...
|
I need to combine a string along with a list of strings into a tuple so I can use it as a dictionary key. This is going to be in ... |
Say I do the following:
>>> a = foo@bar.com
>>> uname, domain = a.split('@')
But what if I only ever want domain, and never uname? For example, if I only ever wanted uname and ... |
I tried this:
def string_to_value(self, old_value, distribution_type, new_value_str):
parameter_names = distribution_type.parameters # a list of string
try:
parameter_values ...
|
I've been given some strings to work with. Each one represents a data set and consists of the data set's name and the associated statistics. They all have the following form:
s= ...
|
y="Peter Email: peter@rp.com Phone: 91291212"
z="Alan Email: alan@rp.com Phone: 98884444"
w="John Email: john@rp.com Phone: 93335555"
add_book=str(y) ,"" + str(z) ,"" + str(w)
**I am trying to add a contact into my address book but I ... |
Here is the code:
#!/usr/bin/env python
import json
import sys
import os
import parser
sys.path.append('Z:\_protomotion\Prog\HelperScripts')
import GetDir
sys.path.append('Z:/Blender_Roto')
filename = 'diving_board.shape4ae'
infile = 'Z:/Blender_Roto/'
#import bpy
#from mathutils import Vector
#below are taken from mocha export
x_width =2048
y_height = 778
z_depth = 0
frame = 20
import re
data_directory ...
|
I have this code:
prefixes = "JKLMNOPQ"
suffix = "ack"
for letter in prefixes:
if letter in ("O", "Q"):
print letter ...
|
I have the following code:
string = "ad\23e\4x{\s"
data = (string,)
When I print the data my string in the tuple has an extra slash for each slash a total of 6 back slashes.
How ... |
Part of the problem is that not all of the 4 items in EnvList need to exist. For example, if I want to pick just the Solaris servers out of the ServerList then EnvList will only contain ['Solaris'] EnvList is created through a series of menus from which the user will pick only then EnvList items that they need. |
|
Tuples can be used to store several pieces of information in one place. For example, the tuple (pair in this case) ('Meaning of life', 42) contains two pieces of information - a string and an integer. Write a function len_str that takes a string as an argument and returns a pair consisting of the length of the string and the string ... |
Hi. I'm having a mental meltdown managing strings and tuples. What I'm trying to do is turn a string into a tuple to then send to db. String is 2005,1,50,4,Andrew Thompson,1,St Kilda,13,13,10,10,23,23,6,6,0,0,2,2,0,0,1,1,0,6,91,9 When I split the string by commas, I get a list list_values is ['2005', '1', '50', '4', 'Andrew Thompson', '1', 'St Kilda', '13', '13', '10', '10', '23', '23', '6', ... |
def returnChangedTuple(myString, myTuple): myTuple = list(myTuple) listOfEqualities = myString.split(',') listOfPairs = [] for i in listOfEqualities: listOfPairs.append(str(i).split('=')) print listOfPairs for i in listOfPairs: ... |
thanks all. I try to make it simple, I have file consist following tuple:(12,33,57),(322,44),(23,77). I want to access all that file and make it as E for first tuple(12,33,57), P for second tuple tuple(322,44) and pk for third tuple. I just using following code : f=open('tuplefile.txt','r') E,P,pk=f.readline() but I got error message. when i access it as one tuple it success ... |
def load_parts(): file = open ("parts.txt", 'U') parts = [] # make a list called parts while True: line = file.readline() if not line: break ID = {} ... |