string « tuple « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » tuple » string 

1. Check if input is a list/tuple of strings or a single string    stackoverflow.com

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 ...

2. Python converts string into tuple    stackoverflow.com

Example:

regular_string = "%s %s" % ("foo", "bar")

result = {}
result["somekey"] = regular_string,

print result["somekey"]
# ('foo bar',)
Why result["somekey"] tuple now not string?

3. How do i return a quoted string from a tuple?    stackoverflow.com

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 ...

4. Why are python strings and tuples are made immutable?    stackoverflow.com

I am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable?

5. Python: check if an object is a list or tuple (but not string)    stackoverflow.com

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 ...

6. How to transform tuple of string(object locations) to dictionary of objects in python    stackoverflow.com

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 ...

7. python: cannot concatenate 'str' and 'tuple' objects (it should works!)    stackoverflow.com

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 ...

8. Why does adding a trailing comma after a string make it a tuple?    stackoverflow.com

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',). ...

9. Tuple to string    stackoverflow.com

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!

10. Finding the index of a string in a tuple    stackoverflow.com

Tup = ('string1','string2','string3')
My program returned string2 how do I get it's index within Tup?

11. String Concatenation in Python    stackoverflow.com

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 ...

12. Read in tuple of lists from text file as tuple, not string - Python    stackoverflow.com

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 ...

13. replace empty string(s) in tuple    stackoverflow.com

Is there an easy way (hopefully a one liner) to replace '' with something like '-'?
Many thanks.

tup = (1,2,'ABC','','','','text')

14. Python string interpolation and tuples    stackoverflow.com

Which of these Python string interpolations is proper (not a trick question)?

  1. '%s' % my_string
  2. '%s' % (my_string)
  3. '%s' % (my_string, )
If it varies by version, please summarize.

15. python: How to determine if a string contains a tuple?    stackoverflow.com

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:

  1. a regex
  2. call eval ...

16. Create a tuple from a string and a list of strings    stackoverflow.com

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 ...

17. Python: Using split on a string and returning a tuple?    stackoverflow.com

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 ...

18. What is the best way to parse a tuple from a string in Python?    stackoverflow.com

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 ...

19. Python Regex to Parse String and Return Tuple    stackoverflow.com

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= ...

20. Find a way to add a string to a tuple    stackoverflow.com

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 ...

21. Controlling my output    stackoverflow.com

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 ...

22. Tuples, checking for a letter in a string    stackoverflow.com

I have this code:

prefixes = "JKLMNOPQ" 
suffix = "ack" 

for letter in prefixes: 
    if letter in ("O", "Q"):
        print letter ...

23. Python: string is escaped when creating a tuple    stackoverflow.com

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 ...

24. Check if a tuple contains a string    bytes.com

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.

26. Basic String and Tuple problem    python-forum.org

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 ...

27. Wrestling with strings and tuples.    python-forum.org

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', ...

28. change given string to desired tuple    python-forum.org

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: ...

29. reading string file as tuple    python-forum.org

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 ...

30. Strings, Tuples, and Dictionarys-- Help plz    python-forum.org

def load_parts(): file = open ("parts.txt", 'U') parts = [] # make a list called parts while True: line = file.readline() if not line: break ID = {} ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.