Python 3 Read from Standard Input (stdin) Like C or Java

I will be using Python3 to read from standard input (or console). I will present two ways of doing this.

First Example

Input (data.txt)

First line of input will contain an integer which tells how many of lines (of data) will follow up. In each of the following lines, there will be one integer and and one floating-point (decimal) number, separated by a space:

1 2.3
3 4
5 6.0

Code (

if __name__ == '__main__':
    # Reading the first line and converting it to an integer
    num_entries = int(input())

    # Running a for loop to read each of the following lines
    for i in range(num_entries):
        current_line = input()
        # Getting the two values separated by space in variables `a` and `b`
        a, b = current_line.split()
        a, b = int(a), float(b)
        print(a, b)

Run the program

python3 < data.txt

Second Example

Input (data.txt)

In this example, data file exactly looks like the one from first example, except that the first line is missing. Which means, we do not know how many data to read. We would have to run a while loop to read lines till there is and EoF (End of File) which tells us there is nothing more to read.

1 2.3
3 4
5 6.0

Code (

if __name__ == '__main__':
        # Running a while loop since we don't know how many lines to read.
        while True:
            current_line = input()
            # Getting the two values separated by space in variables `a` and `b`
            a, b = current_line.split()
            a, b = int(a), float(b)
            print(a, b)
    except EOFError:
        # There is nothing more to do when we reach End of File (EOF)


python3 < data.txt

Concluding Notes

  • You can run the programs without saving input data in a file. Just type python3 and then enter data.
  • Be sure to use Python 3 only as the code will not work in Python 2
  • We are using input() built-in method of Python 3 which reads a single line and returns it as a string. So we have to convert them to appropriate data type (int/float).

From MDN Work Weekend @ Paris

Mozilla Developer Network (MDN) has been my first priority of contribution for more than a year. Specially, since I started feeling the way that contribution for the developer documentations and keeping them up-to-date in my native language is of utmost importance. Thanks to Mozilla and specially Ali for inviting me to join the first MDN work weekend at Paris, from March 7 to 9.

For those who don’t know what the MDN is: it is the home of HTML, CSS, JavaScript, Web API and other open-web standards’ documentation! Get Involved!

As a part of preparation, I, with the help of MDN task force members here in Bangladesh, ran a survey to understand how well local developers know MDN, how they use it everyday, and how they contribute to it. I was not able to present the survey result at the work weekend due to insufficient response, but I hope to publish the results soon, as now the survey has got more attention from local audience.

Are you a Bangladeshi web developer or CS student? Help us improve MDN for Bangladeshi developers by taking part in this short survey!

But my journey to Paris was not smooth. First, I got visa valid from the wrong dates and I had to change my flight, so that I have valid visa when I enter Paris. Next, my flight was delayed for bad weather conditions and I missed my connecting flight from Dubai. I had to stay a whole day at Dubai and I received at Paris the next day, at 2 PM in the afternoon! I was so much frustrated that once I thought I would go back from Dubai instead of keep trying. But then, I decided that I have to make most of it, so as soon as I arrived at Paris I checked in to my hotel and walked directly to Mozilla space at Paris.

Experience at Paris Mozilla space was awesome. Though I had very little time, I quickly joined Jeremie’s web literacy map session – experience at the session was wonderful. We had to figure it out what complete new learners must have and would be nice to have in order to make a website! Now, there is this MDN glossary which was a fantastic idea for new learners.

The next day I arrived early at the office. I was trying my best to pick up works. I spent most of the time with Kensie, Kaustav and Priyanka figuring out next steps for Dev Derby contest. I also had some inputs for MDN events as I had run localization sprint in Bangladesh. At afternoon everyone presented their works, it was really amazing to see so many outcomes in just 3 days. At the same time, I also felt bad about my flight incidents for which I missed most of the work weekend.

We had these fantastic dinners at Paris. I met these amazing people whom I’ve always wanted to meet, and having time with them has been the most inspiring thing that have ever happened to me, and I’m thriving to build the local contributor base here in my country for MDN!



Mozilla Awareness Booth at Ahsanullah University

Mozilla Awareness Booth @ AUST, Dhaka

Returned happily from Mozilla Awareness Booth at Ahsanullah University of Science & Technology (AUST), Dhaka. I returned early, Mozilla Bangladesh community fellows are still there, talking to buzzing students, making them aware of Mozilla missions and awesome products, and helping them to connect to us back by our Facebook group & mailing lists.

I’ll congratulate Ratul as this was his first event after being a rep and also Noor vai, Shuvo, Rifaz and Fuad for always being busy in the booth, talking to the students and being so much motivated!

There was little to do for me other them talking to the students about the MDN activities we’re doing here and web-dev stuffs, so I took some photos at the booth. :)

MDN L10N first Event at Bangladesh

Event report: MDN L10N Boost-Up

Yesterday, we participated at long anticipated MDN Localization Boost-Up event. Organized by Mozilla Bangladesh localization team and attended by promising localizers – both new and active Mozillians. Number of new Mozillians was slightly greater than already-contributors – disappointed us a bit but was acceptable as many could not join due to politically unstable situation.

Organizers reached event venue at early 9:00, we prepared venue. People started showing up from 10:30. We maintained this etherpad to keep track of new localizers and who localized what! Took lunch & prayer break at 1:00 PM. Lunch menu was mouth-watering. :-)

Event resumed at 2:00 PM and continued till 4:30 PM. We ended our program by awarding most-effective contributors T-shirts we designed. We took group photo and returned home, with determinations to continue localization effort.

Event photos can be found at our Facebook Page.

And finally, I’d express my gratitude to those without whose support this event would remain a dream: Zobayer for going through all the hassles of arranging the venue and co-ordinating. Noor vai for the T-shirts and banner, Rahid for the food, MAK vai for the coordinations and support and the last-minute banner design, Firoz for the T-shirt designs, Shuvo, and many other volunteers. These guys not only helped arranging the event but made it fruitful with their presence, guiding new contributors to keep  the web open.

PS: Though there were many new mozillians, only 6 registered in the reps page. But I think that’s sufficient to mail Konstantina for a dino. :-P

Related links:

Avro for Ubuntu 13.10

Recently I got Ubuntu 13.10 and was looking for Avro keyboard… but got frustrated seeing no support from the Avro website. Finally, with help from a ticket there and my friend Rafi Kamal, I made Avro working:

1. Download and install Avro Saucy

32 Bit:

64 Bit:

2. Type “Text Entry” from the dashboard

Press windows key to get the dashboard

3. Click the + button and select Benglai (Avro Phonetic)


Mozilla Summit Diary – 2013 :)

It’s been a while since we came back from “the Summit” – gathering of almost 1800 Mozillians in 3 different cities, where we shared the common view, discussed what we’re doing and set goals for the upcoming days. Among fellow Mozillians from my country Bangladesh, we flew to Santa Clara, SF on 3rd of the October. It was so great to finally meet with the faces I see behing IRC nicks and mails in the list. We reached Santa Clara Marriott (venue for the summit at Santa Clara) by afternoon, and was greeted with welcome bag, and smiling faces :) . After dinner, we (four from Mozilla Bangladesh community) kind of explored the city. Visited Apple store where MAK vai bought his new Mac Air and I bought a sim card.

Next day we were on a photo walk, in the Silicon Valley! It was difficult to control the group as everyone was busy taking snaps, so we could not explored much but it was amazing anyway. Being back to hotel, after taking breakfast, we were in the California Ballroom,  the great room was decorated nicely with two big screens. Mitchell Baker has always been a great speaker, and personally, I was happy for it as the starting of the Summit program. Later, we had World Fair and we had to prepare our stall – Bangladesh stall! We took 2 spots, one dedicated for Localization, Firefox OS and apps activities and another one focusing on the contribution and WebMaker activities. We received great enthusiasm from the audience. After the fair, it was time for lunch. Cuisine here is quite different from ours, still I liked it and made my stomach filled with :).

There were different open sessions, and we decided to divide and attend the sessions we individually were interested in. The plan is, we’re arranging a post summit meet-up in Bangladesh this Friday, to share the ideas we got from the Summit. This way, everyone from our community who is interested in what I got from the Summit, will be able to know. I’m planning to give a presentation on Mozilla services, and will talk on MDN localization boost up in our community.

There are lots of things to share for which I’ll write separate posts, perhaps.

If you’d like to spend your time viewing some photos of the summit, specially of MozillaBD stall from world fair, they’re here!