Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6710107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:57:42+00:00 2026-05-26T07:57:42+00:00

import os try: os.path.exists(E:/Contact) #Check if dir exist except: os.mkdir(E:/Contact) #if not, create def

  • 0
import os
try: 
    os.path.exists("E:/Contact") #Check if dir exist     
except:
    os.mkdir("E:/Contact")   #if not, create

def add(name,cell,email): #add contact
    conPath0 = 'E:/Contact'
    conPath1 = '/ '
    conPath1b =  conPath1.strip()
    conPath2 = name+'.txt'
    conPath = conPath0+conPath1b+conPath2
    file = open(conPath,'w')  
    file.write('Name:'+ name+'\n') #write into file
    file.write('Cell:'+ cell+'\n')
    file.write('Email:'+ email+'\n')
    file.close()
def get(name):  #get contact
    conPath0 = 'E:/Contact'
    conPath1 = '/ '
    conPath1b =  conPath1.strip()
    conPath2 = name+'.txt'
    conPath = conPath0 + conPath1b + conPath2
    try:
         os.path.exists(conPath) #check if exist
         file = open(conPath,'r')
         getFile = file.readlines()
         print(getFile)
    except:
        print("Not Found!")
def delete(name): #delete contact
    conPath0 = 'E:/Contact'
    conPath1 = '/ '
    conPath1b =  conPath1.strip()
    conPath2 = name+'.txt'
    conPath = conPath0 + conPath1b + conPath2
    try:
         os.path.exists(conPath) 
         os.remove(conPath) 
         print(name+"has been deleted!")
    except:
        print("Not Found!")

When I type this:

add('jack','222','ds@gmail.com')

I got this:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    add('jack','222','ds@gmail.com')
  File "E:/lab/t.py", line 13, in add
    file = open(conPath,'w')
IOError: [Errno 2] No such file or directory: 'E:/Contact/jack.txt'

I have tried E:\Contact it stil does not work.
And I have ran it successfully for the first time. But no more.
I am a newbie forgive me if my code sucks. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:57:43+00:00Added an answer on May 26, 2026 at 7:57 am

    If the path does not exist, the os.path.exists call returns False rather than throwing an exception. So the first part of the code do not work as intended. Use this instead

    if not os.path.exists("E:/Contact"):
        os.mkdir("E:/Contact")  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take Django for instance, in manage.py : try: import settings except ImportError: sys.stderr.write(Error: Can't
The only nice way I've found is: import sys import os try: os.kill(int(sys.argv[1]), 0)
I am currently using PIL. from PIL import Image try: im = Image.open(filename) #
I try to import sql script, generated with Server Management Studio, into SQL Compact
When I run a mysqldump command on my database and then try to import
I have a problem using the SSIS. I try to import data from database
When I try to compile this: import java.awt.* ; class obj { public static
I've included: #import QuartzCore/QuartzCore.h but when I try to build, I get the error
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I've written this to try and log onto a forum (phpBB3). import urllib2, re

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.