I'm trying to think in Python, but am stumped here...
What is the equivalent for the following if you are dealing with a tuple
of non-strings? import string foo = ( '1', '2', '3' ) string.join( foo, '.' )
'1.2.3'
With a tuple of integers, this fails with a traceback as below:
bar = ( 1, 2, 3 ) string.join( bar, '.' )
Traceback (most recent call last):
File "<pyshell#1 1>", line 1, in -toplevel-
string.join( bar, '.' )
File "C:\Python23\Li b\string.py", line 135, in join
return sep.join(words)
TypeError: sequence item 0: expected string, int found
--PLB 3 10524
"Peter L. Buschman" wrote: I'm trying to think in Python, but am stumped here...
What is the equivalent for the following if you are dealing with a tuple of non-strings?
import string foo = ( '1', '2', '3' ) string.join( foo, '.' )
'1.2.3'
With a tuple of integers, this fails with a traceback as below:
Try this instead, using old and new style Python:
string.join(map (str, foo), '.')
or
'.'.join([str(x) for x in foo])
-Peter
"Peter L. Buschman" <pl*@iotk.com > schrieb im Newsbeitrag
news:1a******** *************** ***@posting.goo gle.com... I'm trying to think in Python, but am stumped here...
What is the equivalent for the following if you are dealing with a tuple of non-strings?
import string foo = ( '1', '2', '3' ) string.join( foo, '.' ) '1.2.3'
With a tuple of integers, this fails with a traceback as below: bar = ( 1, 2, 3 ) string.join( bar, '.' )
try:
foo = (1,2,3,4,5,6)
".".join([str(x) for x in foo])
HTH
Ciao Ulrich
Awesome! Thanks guys :)
--PLB This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jfj |
last post by:
Yo.
Why can't we __setitem__ for tuples?
The way I see it is that if we enable __setitem__ for tuples there
doesn't seem to be any performance penalty if the users don't use it
(aka, python performance independent of tuple mutability).
On the other hand, right now we have to use a list if we want to
__setitem__ on a sequence. If we could use tuples in the cases where
we want to modify items but not modify the length of the sequence,
|
by: seberino |
last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows.
This causes confusion for 1 item tuples since (5) can be interpreted
as a tuple OR as the number 5 in a mathematical expression
such as x = (5) * (4+6).
Wouldn't it have been better to define tuples with <>'s or {}'s or
something else to avoid this confusion??
Perhaps ()'s are a good idea for some other reason I don't know?
|
by: Steven D'Aprano |
last post by:
I'm trying to understand the use of tuples in function argument lists.
I did this:
>>> def tester(a, (b,c)):
.... print a, b, c
....
>>> tester(1, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
|
by: thilbert |
last post by:
All,
I have a perplexing problem that I hope someone can help me with.
I have the following table struct:
Permission
-----------------
PermissionId
Permission
|
by: Dam |
last post by:
Using SqlServer :
Query 1 :
SELECT def.lID as IdDefinition,
TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour
FROM serveur.Data_tblDEFINITIONTABLEDECODES def,
serveur.Data_tblTABLEDECODEAUNEVALEUR TDC_AUneValeur
where def.TYPEDETABLEDECODES = 4
| |
by: xixi |
last post by:
when i create a join view like this
create view JV104FZ.APJTINM1 (APAM32, APNO20, APQY05, PONO01, PONO05,
PONO19, POCD01, POCD13, systimestamp, loginname, id ) as select
JV104FZ.APPTINM.APAM32, JV104FZ.APPTINM.APNO20,
JV104FZ.APPTINM.APQY05, JV104FZ.APPTINM.PONO01,
JV104FZ.APPTINM.PONO05, JV104FZ.APPTINM.PONO19,
COALESCE(JV104FZ.POPTOL.POCD01, ' '), COALESCE(JV104FZ.POPTOL.POCD13,
' '), JV104FZ.POPTOL.systimestamp,...
|
by: Martin |
last post by:
Hello everybody,
I have the following question.
As a join clause on Oracle we use " table1.field1 = table2.field1 (+) "
On SQL Server we use " table1.field1 *= table2.field1 "
Does DB2 have the same type of operator, without using the OUTER JOIN
syntax ?
|
by: Mike Meyer |
last post by:
It seems that the distinction between tuples and lists has slowly been
fading away. What we call "tuple unpacking" works fine with lists on
either side of the assignment, and iterators on the values side. IIRC,
"apply" used to require that the second argument be a tuple; it now
accepts sequences, and has been depreciated in favor of *args, which
accepts not only sequences but iterators.
Is there any place in the language that still...
|
by: fff_afafaf |
last post by:
Do you know is it possible to put different kinds of tuples to one
container?
E.g. to a vector?
(The lengths of the tuples are different, and also the types in the
tuples are different..
-Is it possible to make a pointer, which can point to all of these
tuples?)
#include <tr1/tuple>
|
by: Jane T |
last post by:
I appreciate how difficult it is to resolve a problem without all the
information but maybe someone has come across a similar problem.
I have an 'extract' table which has 1853 rows when I ask for all rows where
period_ = 3. The allocation table for info has 210 rows.
I have two scripts below. The first script where I specify a period on a
join, brings back 1853 lines and works. The second script where I specify
the period in the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |