0

I am a novice with Python. I am trying to output a first initial last name for an email address. Such as:

John Doe jdoe@domain.com

I am using the following Python:

primary_mail = '%(givenname)s'[0:1]%(surname)s@%(domain)s

But when it outputs I don't get:

jdoe@domain.com

Instead I get some jumbled thing:

params = { "givenname":"Hans", "surname":"Wurst", "domain":"fleischer" }
print "'%(givenname)s'[0:1]%(surname)s@%(domain)s" % params

Can someone help me? I don't understand Python 100% yet so sorry if this is very novice.

  • It's not clear what are you trying to do and what variables your have. Try standard 2.7 syntax: my_string = "%s@%s" % (username, domain) – Navern Sep 01 '15 at 11:25
  • Hi! I simply want first initial of the "givenname" and combine it with the last name, which is "surname" and add the domain after that. Does that make sense? – Gordon Snappleweed Sep 01 '15 at 11:39
  • 2
    This isn't about **Managing** systems in an business environment and as such is off topic. It may be more approprite for [so] but check their about and faq pages. –  Sep 01 '15 at 11:41
  • check my answer below – Navern Sep 01 '15 at 11:41

2 Answers2

1

Combine each part with the + operator:

>>> params['givenname'][0].lower() + params['surname'].lower() + '@' + params['domain']
'hwurst@fleischer'
leancz
  • 688
  • 5
  • 21
0

For python2.7 it would look like this:

>>> name = "ivan"
>>> lastname = "bobrov"
>>> my_email = "%s@%s" % (name[0:1], lastname)
>>> print my_email
i@bobrov
>>> 

Let me know if you have any questions.

Navern
  • 101
  • 2