Python 3, I want to layout a string to print right aligned. I know I deserve to do this:

print(':>30'.format('string goes here'))and that will make that right-aligned come the 30th column. Yet say I desire it right-aligned come the nth column. I have tried several means to do it, however each way returns one error:

print(':>n'.format('string go here'))gives

ValueError: Unknown layout code 'n' for object of form 'str'and

print(':>0'.format('string goes here'))gives

ValueError: cannot switch native automatic ar numbering to manual ar specificationand

print(':>'.format(n, 'string goes here'))gives

ValueError: Invalid layout specifierSo I'm make the efforts to figure out the right means to happen n as the discussion for how far to the right I want my text aligned. What am ns doing dorn here, and also how carry out I execute it right?




You are watching: Valueerror: cannot switch from automatic field numbering to manual field specification

7 comments
share
save
hide
report
90% Upvoted
Log in or authorize up to leave a comment
Log InSign Up
Sort by: best


*

level 1
· 6y
So close :)

print(':>n'.format('string go here',n=30))
4
Reply
Share
ReportSave
level 2
Op · 6y
danielveazey
Or ...

print(':>x'.format(string goes here', x=n))amirite?


1
Reply
Share
ReportSave
Continue this thread 


level 1
· 6y
If that's the just thing you're act (i.e. This is not component of a larger format string with various other stuff walking on), then together an alternate consider:

4
Reply
Share
ReportSave
level 2
Op · 6y
danielveazey
Cool, thanks. I am actually adding some various other stuff into the the cable format, ns just formed my concern so that didn't have any of the other stuff.


2
Reply
Share
ReportSave
*

r/learnpython
Subdoyourpartparks.org because that posting questions and asking for general advice around your python code.
568k

Members


521

Online


Created Oct 2, 2009
Join
*
*
*
*

*

Top write-ups july 4th 2015Top posts of july, 2015Top short articles 2015
helpdoyourpartparks.org coinsdoyourpartparks.org premiumdoyourpartparks.org gifts
aboutcareerspressadvertiseblogTermsContent policyPrivacy policyMod policy


See more: Mexico Feliz Dia De La Independencia De Mexico, Feliz Dia De La Independencia… Vive Mexico!

Back come Top