Connect with us

Tech News

How to write to a file in Python (TXT, CSV, DOCX)

Dinu das

Published

on

How to write to a file in Python

Writing to recordsdata is among the most necessary issues you’ll study in any new programming language. This lets you save person information for future reference, to control massive information units, or to construct helpful instruments like phrase processors and spreadsheets. Let’s learn how to jot down to a file in Python!

The right way to write to a file in Python – .txt recordsdata

The only technique to write to a file in Python, is to create a brand new textual content file. This may permit you to retailer any string to retrieve later.

To do that, you first open the file, then add the content material you need, after which shut the file to complete.

myFile = open("NewFile.txt", "w+")

myFile.write("Hiya World!")

myFile.shut()

On this instance, we now have opened a brand new file, written the phrases “Hiya World!” after which closed the file.

The “w+” tells Python that we’re writing to a brand new file. If the file already exists, then that file is overwritten. If the file doesn’t exist already, then it is going to be created.

However what if you wish to append (add) to a file that already exists? On this case, you merely swap the “w+” for an “a+”.

You may study extra helpful methods in a earlier article:

This may present you learn how to delete and transfer recordsdata too!

To show the contents of the file, simply use the next two traces:

myFile = open("NewFile.txt", "r")

fileContents == myFile.learn()

The right way to write to different varieties of file

However what you probably have one other sort of file you need to work with, aside from a textual content file? What if you wish to create a brand new spreadsheet file? Or a brand new Phrase doc?

In lots of circumstances, you merely have to study the formatting utilized by a selected file-type after which emulate this. For instance, CSV recordsdata are used to retailer spreadsheets. The title “CSV” really refers back to the method this formatting works: “Comma-Separated Values.”

Briefly, every line represents a row in a database and incorporates a collection of values separated by commas. Every comma represents the beginning of a brand new column or cell!

You may, subsequently, save a bunch of knowledge utilizing the very same technique you used to create your textual content file, however guarantee to insert commas and new-lines in the suitable place. For those who then save the file as “.CSV” then it should open in Excel if you click on on it!

The identical goes for a lot of different varieties of file. For instance, you would create a HTML file this fashion through the use of triangular tags to outline headers, daring textual content, and different fundamental formatting!

Many builders will create their very own codecs for storing information particular to their creations. Now you understand how to jot down to a file in Python no matter the kind of file!

Be taught extra about CSV recordsdata in Python right here:

The right way to write to a file in Python with modules

In fact, some recordsdata are going to include extra complicated formatting than others. For instance, if you wish to write a .Doc file in Python, you’ll come unstuck! Open a Phrase doc in a textual content editor and also you’ll see that Microsoft makes use of a whole lot of complicated formatting and annotation to outline the format and add further data.

That is the place modules are available!

First, set up the module you need by way of pip. You are able to do this through the use of the next command:

pip set up python doc-x

In case you are working from a command line in Home windows, attempt:

python –m pip set up doc-x

Now in your Python code you are able to do the next:

import docx

mydoc = docx.Doc()

mydoc.add_paragraph("Hiya World!")

mydoc.save("D:/NewHelloDoc.docx")

This may write “Hiya World!” to a doc after which shut it! You can even do another, extra complicated formatting:

mydoc.add_heading("Header 1", zero)

mydoc.add_heading("Header 2", 1)

mydoc.add_heading("Header three", 2)

mydoc.add_picture("D:/MyPicture.jpg", width=docx.shared.Inches(5), top=docx.shared.Inches(7))

No matter the kind of file you need to work with, you’ll virtually all the time discover a module that may deal with it for you. These are often free to make use of and include documentation you’ll be able to route by! That’s simply one other of the wonderful issues about coding in Python!


And that’s learn how to write to a file in Python! For those who’re having fun with studying Python, then why not take your schooling to the following degree? We’ve compiled an inventory of the most effective on-line Python programs the place yow will discover some wonderful reductions. Test it out!

Tech specialist. Social media guru. Evil problem solver. Total writer. Web enthusiast. Internet nerd. Passionate gamer. Twitter buff.

Tech News

Top 10 Best Boombox Cd Players 2020

Dinu das

Published

on

1. Magnavox MD6972 CD Boombox with Digital AM FM Radio Color Changing Lights

  • Colour altering lights pulsate to the beat and liquid crystal display show with again mild
  • Hook up with any audio system through three.5mm aux in port + headphone jack
  • High loading cd participant with digital pll am/fm stereo radio
  • Cd-r/cd-rw appropriate
  • Ac operation (twine included) or dc operation (makes use of eight x c dimension batteries, not included)

2. LONPOO CD Player Portable Boombox with FM Radio/USB/Bluetooth/AUX Input and Earphone Jack Output

  • 【moveable boombox& wi-fi connection】play music wirelessly from bluetooth units, you can also use the boombox outside with four*um2-c 1.5v batteries insert. (battery no included)
  • 【excessive configuration & multi-function】full liquid crystal display display show, stereo audio system,digital digital buttons, earlier / subsequent tune, auto-stop (recording playback) perform.
  • 【top-loading cd player】cd/mp3 participant, appropriate with cd-r/cd-rw
  • 【number of audio modes & earphones output】assist fm radio/ usb / aux-in enter, a key change, straightforward to make use of. assist headphone jack output from cd participant, get pleasure from your favourite tune in non-public, won’t disturb different individuals.
  • 【wide selection of purposes 】swimsuit for a wide range of places: finding out, household social gathering, valentine’s date, private leisure, dance, health,outside actions, and so forth. it is a good reward for youths, elders, famliy and pals!

3. Sylvania SRCD243 Portable CD Player with AM/FM Radio, Boombox (Blue)

  • Skip/search perform, repeat 1/all perform
  • Aux in jack – permits you to play music from any audio system
  • This unit operates on eight x ‘c’ (um-2) dimension batteries or from the included ac120v/60hz line energy provide
  • Transportable cd boombox with am/fm radio
  • Led show.word: kindly refer the consumer handbook earlier than utilization of the product.
  • Pallet amount: 32

4. Lauson CP546 Portable Stereo Boombox CD Player with Radio | USB & MP3

  • Usb boombox participant: usb port permits you to play mp3s from flash drives and join your units. straightforward to make use of, best for youths and on a regular basis use.
  • Transportable cd participant: ac / dc energy provide – you should utilize them exterior,journey or inside your private home and headphone shops. fordable carrying deal with. works with energy or batteries 6 x u-2 (not included)
  • Cd participant: excessive compatibility, a cd participant moveable performs audio cds, cd-rs, cd-rws or mp3 cd participant , led cd observe show.
  • Radio cd participant: digital fm radio with 20 presets and digital liquid crystal display display. tuner whit telescopic antenna. straightforward to make use of, best for youths and on a regular basis use.
  • Conexions: cd participant with headphones jack, auxiliary enter jack for connecting your ipod, mp3 music or different digital audio gamers, output: 2 x 1.5w rms. built-in audio system.

5. Jensen CD-475B Portable Sport Stereo Boombox CD Player with AM/FM Radio and Aux

  • ✅►skip/search, ahead and again, repeat 1 or all, programmable reminiscence
  • ✅► auxiliary enter jack for connecting your ipod, mp3 or different digital audio gamers in-built audio system
  • ✅►top loading cd participant, cd-r/rw appropriate, led cd observe show
  • ✅►am/fm stereo receiver, foldable carrying deal with, telescopic antenna, stereo headphone jack
  • ✅►power twine included: ac120 60hz or 6 x ‘c’ (um-2) batteries (not included)

6. GPX BCA209B Portable Am/FM Boombox with CD and Cassette Player, Black

  • Auto-stop at tape finish; liquid crystal display show with white backlight; data from radio and cd
  • Consists of ac energy cable; dc battery energy: requires 6 c batteries (not included)
  • Transportable boombox with am/fm radio, cd and cassette participant; top-load disc participant
  • Highly effective built-in stereo audio system; steel speaker grill
  • Handy carry deal with for portability, black

7. Jensen CD-555 White/Silver CD Bluetooth Boombox Portable Bluetooth Music System with CD Player

  • Bluetooth wi-fi model helps all the most recent bluetooth units
  • Programmable reminiscence fm stereo receiver bass increase headphone jack
  • High loading cd participant cd-r/rw appropriate helps a2dp, avrcp
  • Blue led cd observe show skip/search, ahead and again repeat 1 or all
  • Auxiliary enter jack for connecting your ipod, mp3 or different digital audio gamers built-in carrying deal with

8. Portable CD Player with Bluetooth, Wall Mountable CD Music Player Home Audio Boombox

  • 【distinctive design】inventive wall mountable design with pull change, makes it simpler to be mounted on the wall, traditional and area saving. plus, there’s a desk stand and a distant management included. you’ll be able to place the cd participant in the lounge, eating room, bed room or wherever you like. pull the ability cable to show it on, and revel in a musical way of life!
  • 【excellent gift】presents for youths, elders, dad and mom and pals and so on. appropriate for language studying, prenatal training / antenatal coaching, early training, fm radio broadcast, cd/usb/mp3 music participant and residential or espresso home ornament. with 1 12 months interval and 30 days a refund, you may be given an incredible high quality of after-sales service.
  • 【5 in 1 function】1) moveable cd participant, 2) fm radio, three) bluetooth hifi speaker, four) mini dwelling boombox, 5) usb flash drive participant. it provides you all of the comfort by fashionable tech. you’ll be able to play your favourite music in a celebration/studio/therapeutic massage/yoga/informal time, or simply use it as a radio to get native information.
  • 【broad compatibility】1) helps cd/cd-r/cd-rw/mp3/wma, every kind of cds hassle-free. 2) built-in bluetooth connects with bluetooth-enabled units comparable to cell/pill. three) aux in/out and three.5mm audio enter jack: appropriate for all audible units. four) distant management: helps a distance of 5 meters. 5) usb port: helps usb flash. word: this cd participant comes and not using a blue…
  • 【package deal & after-sale service】1 x moveable cd participant, 1 x usb adapter, 1 x distant management ,1 x wall-mounted package, 1 x wall-mounted plate, 1 x desk stand, 1 x three.5mm male to male audio jack cable, 1 x consumer handbook and 30-day a refund and 12-month after-sale service from manufacture. please word: insulator must be taken out earlier than utilizing the distant.

9. Portable CD Player with Bluetooth, Wall Mountable CD Music Player with Dust Cover

  • 【led show & timer setting】inventive wall mountable design with mud cowl and led show display, makes it handy to know which mode it’s. it reveals totally different modes for you select, comparable to cd, usb, bluetooth , fm radio and line modes. plus, you should utilize the timer button(proven as a clock emblem) within the distant management to set a time interval from 30minutes to180 minutes for the…
  • 【bluetooth cd player】it turns into a hifi bluetooth speaker whereas its built-in bluetooth receiver connects with bluetooth-enabled units comparable to cell/pill. with three.5mm audio jack, you may as well join the cd participant to different exterior wired audio system. and the distant management helps a distance of 5 meters. (word: this cd participant is just not with a bluetooth transmitter perform…
  • 【5 in 1 function】1) moveable cd participant, 2) fm radio, three) bluetooth hifi speaker, four) mini dwelling boombox, 5) usb flash drive participant. it helps to participant cd,cd-r,cd-rw,cd-g,mp3,wma, every kind of cds hassle-free. it provides you all of the comfort by fashionable tech. you’ll be able to play your favourite music in a celebration/studio/therapeutic massage/yoga/informal time, or simply use it as a radio to get loc…
  • 【humanized design with mud cover】inventive wall mountable design with mud cowl, removes your issues about any cd efficiency points attributable to mud buildup. the cd participant comes with a wall-mounted plate, a compact desk stand, a distant management and a three.5m energy cable. so you’ll be able to place/mount the moveable cd participant in the lounge, eating room, kitchen, bed room, sitti…
  • 【excellent gift】presents for youths, elders, dad and mom, pals and pregnant girls and so on. the cd participant helps distant management inside 5 meters, a-b repeat, tune quantity alternative, appropriate for language studying, prenatal training / antenatal coaching, early training, fm radio broadcast, cd/usb/mp3 music participant and residential or espresso home ornament. you may be given an incredible high quality o…

10. Sony Stereo CD/Cassette Boombox Home Audio Radio, Black (CFDS70BLK)

  • Fm/am tuner with digital tuning and 30 station presets, ac and battery energy choices with as much as 19 hours of battery life, aux audio enter permits you to join digital music gamers
  • Energy provide 1 x ac energy twine (120 vac, 60 hz) or 6 x r14/dimension c dry batteries (9 vdc); requires 6 c batteries; works properly and lengthy with polaroid c batteries
  • Get pleasure from full-function stereo sound, playback cds, cd-r/rw and mp3 cds with shuffle and program features, built-in cassette tape deck with recording perform. word:unplug this equipment throughout lightning storms or when unused for lengthy intervals of time. kindly observe the directions offered within the consumer information.
  • Mega bass increase circuitry enhances low-frequency bass efficiency on the contact of a button, ac energy twine included
  • Be aware: kindly refer the pdfs offered underneath technical specs earlier than use

Continue Reading

Tech News

How a hacker turned a $250 coffee maker into ransom machine

Dinu das

Published

on

With the identify Smarter, you would possibly anticipate a network-connected kitchen equipment maker to be, nicely, smarter than corporations promoting typical home equipment. However within the case of the Smarter’s Web-of-things espresso maker, you’d be improper.

As a thought experiment, Martin Hron, a researcher at safety firm Avast, reverse engineered one of many $250 units to see what sorts of hacks he may do. After only a week of effort, the unqualified reply was: rather a lot. Particularly, he may set off the espresso maker to activate the burner, dispense water, spin the bean grinder, and show a ransom message, all whereas beeping repeatedly. Oh, and by the best way, the one strategy to cease the chaos was to unplug the facility wire. Like this:

What a hacked espresso maker seems like

“It’s doable,” Hron stated in an interview. “It was performed to level out that this did occur and will occur to different IoT units. This can be a good instance of an out-of-the-box drawback. You do not have to configure something. Often, the distributors don’t take into consideration this.”

What do you imply “out-of-the-box”?

This poor IoT coffee maker didn't stand a chance.
Enlarge / This poor IoT espresso maker did not stand an opportunity.

When Hron first plugged in his Smarter espresso maker, he found that it instantly acted as a Wi-Fi entry level that used an unsecured connection to speak with a smartphone app. The app, in flip, is used to configure the machine and, ought to the person select, join it to a house Wi-Fi community. With no encryption, the researcher had no drawback studying how the telephone managed the espresso maker and, since there was no authentication both, how a rogue telephone app would possibly do the identical factor.

That functionality nonetheless left Hron with solely a small menu of instructions, none of them particularly dangerous. So he then examined the mechanism the espresso maker used to obtain firmware updates. It turned out they have been obtained from the telephone with—you guessed it—no encryption, no authentication, and no code signing.

These obvious omissions created simply the chance Hron wanted. Because the newest firmware model was saved contained in the Android app, he may pull it onto a pc and reverse engineer it utilizing IDA, a software program analyzer, debugger, and disassembler that’s one in every of a reverse engineer’s greatest associates. Virtually instantly, he discovered human-readable strings.

“From this, we may deduce there is no such thing as a encryption, and the firmware might be a ‘plaintext’ picture that’s uploaded immediately into the FLASH reminiscence of the espresso maker,” he wrote on this detailed blog outlining the hack.

Taking the insides out

To truly disassemble the firmware—that’s, to rework the binary code into the underlying meeting language that communicates with the , Hron needed to know what CPU the espresso maker used. That required him to take aside the machine internals, discover the circuit board, and determine the chips. The 2 photos beneath present what he discovered:

The circuit board.
Enlarge / The circuit board.

Avast

1 – ESP8266 with AT modem firmware, 2 – STM32F05106 ARM Cortex M0 – main CPU that glues everything together, 3 – I2C EEPROM with configuration, 4 – debug ports and programming interface.
Enlarge / 1 – ESP8266 with AT modem firmware, 2 – STM32F05106 ARM Cortex M0 – principal CPU that glues all the things collectively, three – I2C EEPROM with configuration, four – debug ports and programming interface.

Avast

With the flexibility to disassemble the firmware, the items began to come back collectively. Hron was in a position to reverse crucial capabilities, together with those that test if a carafe is on the burner, trigger the machine to beep, and—most significantly—set up an replace. Under is a block diagram of the espresso maker’s principal parts:

Hron finally acquired sufficient data to jot down a python script that mimicked the replace course of. Utilizing a barely modified model of the firmware, he found it labored. This was his “hiya world” of types:

Avast

Freak out any person

The following step was to create modified firmware that did one thing much less innocuous.

“Initially, we wished to show the truth that this machine may mine cryptocurrency,” Hron wrote. “Contemplating the CPU and structure, it’s definitely doable, however at a pace of 8MHz, it doesn’t make any sense because the produced worth of such a miner could be negligible.”

So the researcher settled on one thing else—a machine that will actual a ransom if the proprietor wished it to cease spectacularly malfunctioning the best way proven within the video. With the advantage of some unused reminiscence area within the silicon, Hron added traces of code that brought on all of the commotion.

“We thought this might be sufficient to freak any person out and make it a really aggravating expertise. The one factor the person can do at that time is unplug the espresso maker from the facility socket.”

As soon as the working replace script and modified firmware is written and loaded onto an Android telephone (iOS could be a lot tougher, if not prohibitively so due to its closed nature), there are a number of methods to hold out the assault. The best is to discover a susceptible espresso maker inside Wi-Fi vary. Within the occasion the machine hasn’t been configured to hook up with a Wi-Fi community, this is so simple as in search of the SSID that’s broadcast by the espresso maker.

Beachhead

As soon as the machine connects to a house community, this advert hoc SSID required to configure the espresso maker and provoke any updates is not out there. Essentially the most simple strategy to work round this limitation could be if the attacker knew a espresso maker was in use on a given community. The attacker would then ship the community a deauthorization packet that will trigger the espresso maker to disconnect. As quickly as that occurs, the machine will start broadcasting the advert hoc SSID once more, leaving the attacker free to replace the machine with malicious firmware.

A extra opportunistic variation of this vector could be to ship deauthorization packet to each SSID inside Wi-Fi vary and wait to see if any advert hoc broadcasts seem (SSIDs are at all times “Smarter Espresso:xx,” the place xx is identical because the lowest byte of the machine’s MAC deal with).

The limitation of this assault, it is going to be apparent to many, is that it really works solely when the attacker can find a susceptible espresso maker and is inside Wi-Fi vary of it. Hron stated a method round that is to hack a Wi-Fi router and use that as a beachhead to assault the espresso maker. This assault could be performed remotely, but when an attacker has already compromised the router, the community proprietor has worse issues to fret about than a malfunctioning espresso maker.

In any occasion, Hron stated the ransom assault is just the start of what an attacker may do. With extra work, he believes, an attacker may program a espresso maker—and presumably different home equipment made by Smarter—to assault the router, computer systems, or different units related to the identical community. And the attacker may most likely do it with no overt signal something was amiss.

Placing it in perspective

Due to the restrictions, this hack isn’t one thing that represents an actual or fast risk, though for some folks (myself included), it’s sufficient to steer me away from Smarter merchandise, not less than so long as present fashions (the one Hron used is older) don’t use encryption, authentication, or code signing. Firm representatives didn’t instantly reply to messages asking.

Reasonably, as famous on the high of this put up, the hack is a thought experiment designed to discover what’s doable in a world the place espresso machines, fridges, and all different method of house units all connect with the Web. One of many fascinating issues concerning the espresso machine hacked right here is that it’s not eligible to obtain firmware updates, so there’s nothing homeowners can do to repair the weaknesses Hron discovered.

Hron additionally raises this essential level:

Moreover, this case additionally demonstrates probably the most regarding points with trendy IoT units: “The lifespan of a typical fridge is 17 years, how lengthy do you suppose distributors will help software program for its good performance?” Certain, you possibly can nonetheless use it even when it’s not getting updates anymore, however with the tempo of IoT explosion and dangerous perspective to help, we’re creating a military of deserted susceptible units that may be misused for nefarious functions reminiscent of community breaches, knowledge leaks, ransomware assault and DDoS.

There’s additionally the issue of realizing what to do concerning the IoT explosion. Assuming you get an IoT gadget in any respect, it’s tempting to suppose that the, uh, smarter transfer is to easily not join the machine to the Web in any respect and permit it to function as a standard, non-networked equipment.

However within the case of the espresso maker right here, that will really make you extra susceptible, since it could simply broadcast the advert hoc SSID and, in so doing, save a hacker just a few steps. Wanting utilizing an old style espresso maker, the higher path could be to attach the machine to a virtual LAN, that means a separate SSID that’s partitioned from the one used usually.

Hron’s write-up linked above offers greater than four,000 phrases of wealthy particulars, a lot of that are too technical to be captured right here. It needs to be required studying for anybody constructing IoT units.

Itemizing picture by Avast

Continue Reading

Tech News

Top 10 Best Marcum Underwater Cameras 2020

Dinu das

Published

on

1. Marcum Recon 5 Underwater Camera Viewing System by MarCum

  • 20 hours of steady runtime
  • Comfortable carry case included
  • 2,500-watts energy
  • Computerized shut-off extends battery life
  • Powered by cr-p2 6-volt lithium battery included

2. MarCum Digital Handheld Sonar

  • Digital camera, cmos sensor, darkwater led and infrared lighting
  • 50 foot digicam cable and on display battery standing, lithium battery w/6 hours of run time
  • 5 inch widescreen flat panel 16:9 facet ratio, hello res colour liquid crystal display
  • 90 diploma subject of view with colour kill
  • Show changes, brightness, distinction sharpness

3. Marcum Recon 5 Underwater Camera Viewing System

  • Wi-fi transmitter base (as much as 300 ft. vary) and marcum manta digicam 1/Three” sony tremendous had ii
  • Totally built-in digicam pinner
  • Marcum deluxe padded smooth case and marcum management app (downloadable)
  • Materials sort: artificial
  • 50 ft. digicam cable with built-in spool reel for cable storage
  • Inside battery-6-Eight hours of run time and 110 volt wall charger

4. Marcum PanCam Camera System-Wi-Fi

  • Decision: 800 x 480 pixels
  • Contains: 50ft digicam cable, smooth pack shuttle, solar protect, 12-volt 7-amp rechargeable battery, Three-stage battery charger and down-view/stabilizer fin
  • 7″ widescreen flat panel monitor and hi-res switchable colour and b/w liquid crystal display video out
  • Contains smooth pack shuttle, solar protect,12-volt 7-amp rechargeable battery, Three-stage battery charger
  • 1 yr guarantee
  • 7 inch widescreen flat panel hi-res monitor options switchable colour and b/w liquid crystal display video out

5. MarCum VS485C LCD Underwater Viewing System, 7″

  • On display show relative path, temp, depth, battery standing, brightness, distinction, sharpness and colour kill
  • Decision 800 x 480 pixels
  • 7″ widescreen vivid show 1080p hd video out hi-res colour liquid crystal display photo voltaic clever know-how
  • Digital camera/cable 1/Three” picture sensor . 01 lux digicam darkish water led lighting down view stabilizer fin 75 ft. digicam cable
  • Contains sunshield 12-volt, 9-amp battery Three-stage battery charger smooth pack shuttle

6. Mission SD Underwater Viewing System

  • Digital camera, cmos sensor, darkwater led and infrared lighting
  • 50 foot digicam cable and on display battery standing, lithium battery w/6 hours of run time
  • 5 inch widescreen flat panel 16:9 facet ratio, hello res colour liquid crystal display
  • 90 diploma subject of view with colour kill
  • Show changes, brightness, distinction sharpness

7. Marcum RC5P Recon 5 Plus Underwater Camera Viewing System

  • 4800 watts peak to peak output energy
  • Patented 12 step interference rejection
  • 6-inch liquid crystal display (640 x 480px) show with four colour palette choices
  • Twin beam Eight/20 diploma ice transducer
  • Computerized backside lock selectable zoom home windows – 5′, 10′, 20′, 40′

8. MarCum Digital Lithium Combo LX-6SLI Digital Lithium Combo, Black

  • 800 x 600 pixel decision
  • Correctly matched four:Three facet digicam & monitor
  • Eight-inch flat panel, hi-res, switchable colour/b&w liquid crystal display
  • Waterproof show with video out
  • Sony tremendous had ii ccd 1/3” picture sensor .01 lux digicam, with 75-feet of cable. on-screen relative path, depth, temp and battery voltage. calibrated for contemporary or salt water use.

9. Marcum VS825SD Underwater Camera with 8 inch screen

  • Materials sort: plastic
  • Included elements: digicam, case, battery, charger
  • Sport sort: fishing

Continue Reading

Trending