Is it better to do:
message = """This is line1.
This is line2
This is line3\n"""
or
message = "This is line1.\n
message = message + "This is line2\n"
message = message + "This is line3\n"
Since the first method does not follow python's clean and easy looking
indentation structure but the second just looks crude and ugly anyway.
If I indent the first version so the text is lined up to match code
indentation then this comes out in the input and isn't aligned there. 21 1354
Hari Sekhon wrote: Is it better to do:
message = """This is line1. This is line2 This is line3\n"""
or
message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n"
Is there any reason you can't do it in one line?
message = "This is line1.\nThis is line2.\nThis is line3.\n"
Hari Sekhon wrote: Is it better to do:
message = """This is line1. This is line2 This is line3\n"""
or
message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n"
Since the first method does not follow python's clean and easy looking indentation structure but the second just looks crude and ugly anyway.
If I indent the first version so the text is lined up to match code indentation then this comes out in the input and isn't aligned there.
How about
message = ("This is line1. "
"This is line2 "
"This is line3\n")
The brackets mean that the lines are automatically treated as
continuous, without the need for the ugly '\' continuation character.
The opening/closing quotes on each line mean that the strings are
contatenated into one long string.
Frank Millman
Frank Millman wrote: How about
message = ("This is line1. " "This is line2 " "This is line3\n")
The brackets mean that the lines are automatically treated as continuous, without the need for the ugly '\' continuation character.
The opening/closing quotes on each line mean that the strings are contatenated into one long string.
Frank Millman
Don't know what happened there - Google seems to have messed up my
indentation.
My intention was that each of the three leading quote marks line up
vertically, but when I read it back via Google Groups, the second two
lines were pushed over to the right.
Frank
Hari Sekhon wrote: Is it better to do:
message = """This is line1. This is line2 This is line3\n"""
or
message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n"
Since the first method does not follow python's clean and easy looking indentation structure but the second just looks crude and ugly anyway.
If I indent the first version so the text is lined up to match code indentation then this comes out in the input and isn't aligned there.
Hi,
msgs = ['This is line1.','This is line2.','This is line3.']
message = '\n'.join(msgs)
Regards,
Laurent.
Frank Millman wrote: How about
message = ("This is line1. " "This is line2 " "This is line3\n")
The brackets mean that the lines are automatically treated as continuous, without the need for the ugly '\' continuation character.
The opening/closing quotes on each line mean that the strings are contatenated into one long string.
Don't know what happened there - Google seems to have messed up my indentation.
My intention was that each of the three leading quote marks line up vertically, but when I read it back via Google Groups, the second two lines were pushed over to the right.
assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation
no matter what font you're using, you can write:
message = (
"This is line1. "
"This is line2 "
"This is line3\n")
whether this is better than """ depends on the situation.
</F>
Fredrik Lundh wrote: Frank Millman wrote:
How about
message = ("This is line1. " "This is line2 " "This is line3\n")
The brackets mean that the lines are automatically treated as continuous, without the need for the ugly '\' continuation character.
The opening/closing quotes on each line mean that the strings are contatenated into one long string.
Don't know what happened there - Google seems to have messed up my indentation.
My intention was that each of the three leading quote marks line up vertically, but when I read it back via Google Groups, the second two lines were pushed over to the right.
assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation no matter what font you're using, you can write:
message = ( "This is line1. " "This is line2 " "This is line3\n")
whether this is better than """ depends on the situation.
</F>
Obvious, now that you mention it.
Thank you.
Frank
Hari Sekhon wrote: Since the first method does not follow python's clean and easy looking indentation structure but the second just looks crude and ugly anyway.
If you want indented and pretty is important to you: from textwrap import dedent as D message = D("""\
This is line1.
This is line2
This is line3
""") message
'This is line1.\nThis is line2\nThis is line3\n'
Usually though I would just make sure that long strings are declared at
module level and not indent them. The backslash after the opening quotes
stops the first line being indented differently:
message = """\
This is line1.
This is line2
This is line3
"""
Hari Sekhon wrote: Is it better to do:
message = """This is line1. This is line2 This is line3\n"""
or
message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n"
Since the first method does not follow python's clean and easy looking indentation structure but the second just looks crude and ugly anyway.
If I indent the first version so the text is lined up to match code indentation then this comes out in the input and isn't aligned there.
What about
message = """
This is line 1
This is line 2
This is line 3
"""
When it is necessary to skip first empty line):
message = """
This is line 1
This is line 2
This is line 3
"""[1:]
When necessary to skip first line _and_ indentation:
message = """
This is line 1
This is line 2
This is line 3
""".replace ('\n ', '\n')[1:] # adjust here '\n ' to indentation
# ^-- gives 'This is line 1\nThis is line 2\nThis is line 3\n'
?
Claudio
Claudio Grondi wrote:
<<<clever stuff to di indentation>>> When necessary to skip first line _and_ indentation: message = """ This is line 1 This is line 2 This is line 3 """.replace ('\n ', '\n')[1:] # adjust here '\n ' to indentation
Riffing on this idea:
message = """
This is line 1
This is line 2
This is line 3
""".replace ("""
""", '\n')[1:]
--Scott David Daniels sc***********@a cm.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):
class C(object): pass
C.__bases__ = bases
dict = 0
|
by: Christopher Benson-Manica |
last post by:
If you had an unsigned int that needed to be cast to a const myClass*,
would you use
const myClass* a=reinterpret_cast<const myClass*>(my_val);
or
const myClass* a=(const myClass*)myVal;
?
|
by: amerar |
last post by:
Hi All,
I can make a page using a style sheet, no problem there. However, if I
make an email and send it out to my list, Yahoo & Hotmail totally
ignore the style tags. It looks fine in Netscape though.....
Question: I've tried linking & embedding the style tags with no luck.
How can I use them inline? I've read that inline style sheets is the
way to go if you want them to work in most email clients.......
|
by: amerar |
last post by:
Hi All,
I posted a question about style sheets, and why certain email clients
were ignoring them. Someone suggested placing them inline. I did
this and get better results, but not what I wanted.
The page still appears properly, and it shows in Netscape Messenger
just fine, but on Hotmail and Yahoo, each <DIV> tag does not appear
where it is supposed to appear.
|
by: KvS |
last post by:
Hi all,
I'm pretty new to (wx)Python so plz. don't shoot me if I've missed
something obvious ;). I have a panel inside a frame, on which a Button
and a StaticText is placed:
self.panel = wx.Panel(self,-1)
self.button = wx.Button(self.panel,-1,"Klikkerdeklik")
self.button.SetPosition((200,40))
self.Bind(wx.EVT_BUTTON, self.VeranderLabel, self.button)
| |
by: rahul8143 |
last post by:
hello,
what is difference between sizeof("abcd") and strlen("abcd")? why
both functions gives different output when applied to same string
"abcd".
I tried following example for that.
#include <stdio.h>
#include <string.h>
void main()
{
char *str1="abcd";
|
by: jamilur_rahman |
last post by:
What is the BIG difference between checking the "if(expression)" in A
and B ? I'm used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?
style A:
....
....
int a = 1;
if(0==a)
{
|
by: pocmatos |
last post by:
Hi all,
While I was programming 5 minutes ago a recurring issue came up and
this time I'd like to hear some opinions on style. Although they are
usually personal I do think that in this case as also to do with making
the code easier to read.
Imagine a function returning void (for example) and it's body is a big
if with lots of special cases:
|
by: Claus Mygind |
last post by:
I want to move some style setting into a javaScript function so I can make them variable but I get "invalid assignment left-hand side" error?
see my question at the bottom of this message.
It works fine when I stream it out in my html page like this:
<DIV
ID="popSearch"
STYLE="
position:absolute;
visibility:hidden;
|
by: MatthewS |
last post by:
I've seen the question raised several times here, but apparently never
answered. Since PyInstance_Check returns False for new-style class
instances, is there a standard procedure for testing this using the C-
Api?
I would greatly appreciate some help with this.
/Matthew
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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: 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...
| |