I have a very specific question. The line:
expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert
in the code below is not working:
# Write data in expenses form
expform_wb = xl.Workbooks.Open(expform_path, Editable=True)
expform_ws = expform_wb.Worksheets('Expense Form')
last_row_ef = expense_items + 15
expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert
expform_ws.Range('Casecode').Value = case_code
expform_ws.Range('D6').Value = name
expform_ws.Range('D7').Value = last_name
expform_ws.Range('D8').Value = datetime.date.today().strftime("%d/%m/%Y")
expform_ws.Range('B16:B' + str(last_row_ef)).Value = date
expform_ws.Range('D16:D' + str(last_row_ef)).Value = descr
In case this helps: the line gets highlighted in PyCharm as "Statement seems to have no effect".
Anyone can help to spot what I am doing wrong?
Thanks!
In this line
expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert
You aren't actually CALLING the function, you are just getting "reference" to it, add () to call it
expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert()
Related
def corrections_fn(request, file, selected_words, corrections):
parser = GingerIt()
user = request.user
document = Document(file.file)
text = ''
for line in document.paragraphs:
matches = parser.parse(line.text)
for obj in matches['corrections']:
misspelled_word = obj['text']
if misspelled_word in selected_words:
correction = selected_words[misspelled_word]
line.text = line.text.replace(str(misspelled_word), str(correction))
else:
if corrections == 'auto':
line.text = line.text.replace(str(obj['text']), str(obj['correct']))
document.save(file.file)
return file
In the file variable, i'm sending the Queryset which contains file(.docx).
resumes = Resume.objects.filter(user=user)
for resume in resumes:
corrections_fn(request=request, file=resume, selected_words=selected_words, corrections="show")
When i try to rewrite the file. It is showing "Unsupported Operation write" error. I searched on internet and i'm not able to find the right document to deal with this type of issue. can any help me on how to solve the issue?
Thank you in advance
Blockquote
I am working on a project where I need to scrape data from a graph that shows the data for 1 day. For example: I want to get al the data for 2017 so I have to enter a new date in the datepicker 365 times. The problem is that although I am very specific in my XPATH call, the script finds way to many webelements. Many of which are not even compliant to my restrictions in my XPATH. This only happens some way into the loop and every loop the script finds more and more web elements.
The code that I am using:
Date_vec = pd.date_range(start="2017-01-01",end="2021-2-28")
DatePicker = web.find_element_by_xpath('/html/body/form/table/tbody/tr/td/table/tbody/tr/td[2]/div/div[1]/div[2]/div[2]/div[2]/div/div[2]/div/table/tbody/tr[2]/td/table/tbody/tr/td[2]/span/input')
month_prev = 0
year_prev = 0
for i in Date_vec:
DatePicker = web.find_element_by_xpath('/html/body/form/table/tbody/tr/td/table/tbody/tr/td[2]/div/div[1]/div[2]/div[2]/div[2]/div/div[2]/div/table/tbody/tr[2]/td/table/tbody/tr/td[2]/span/input')
DatePicker.click()
if i.year != year_prev:
# Year_button = web.find_element(By.XPATH,"//span[#onclick = 'basicDatePicker.ehYearSelectorClick(this)']")
Year_button = web.find_elements(By.XPATH,".//span[#onclick = 'basicDatePicker.ehYearSelectorClick(this)']")
Year_button[-1].click()
Year_choice = web.find_elements(By.XPATH,"//a[normalize-space(text()) ='"+ str(i.year) + "']")
Year_choice[-1].click()
elif i.month != month_prev:
Month_button = web.find_elements(By.XPATH,"//span[#onclick = 'basicDatePicker.ehMonthSelectorClick(this)']")
Month_button[-1].click()
Month_choice = web.find_elements_by_class_name('bdpMonthItem')
Month_choice[i.month-1].click()
Day_button = web.find_elements(By.XPATH,"//a[normalize-space(text()) ='"+ str(i.day) + "' and contains(#class, 'bdpDay')]")
Day_button[-1].click()
time.sleep(3)
month_prev = i.month
year_prev = i.year
For example, the problem arises at the line below:
Day_button = web.find_elements(By.XPATH,"//a[normalize-space(text()) ='"+ str(i.day) + "' and contains(#class, 'bdpDay')]")
This line returns 4 elements of which 2 don't have any text in them. I checked this with the following line.
test1 = [i.text for i in Day_button]
So my question basically is: Why does the line code return 4 elements of which two don't have text while I explicitly tell it to have the current day as text. Any help is appreciated.
edit: for clarity, I added a snip from the datepicker in question:
I am familiar with the Django and I am using Django framework(2.2.2) in one of my website, But I am getting one weird issue for saving record with the foreign key:
I have following two models
class quick_note(models.Model):
note_id = models.AutoField(primary_key=True)
meeting_date = models.DateField(max_length=55)
title = models.TextField(blank = True,null=True)
headline = models.TextField(blank = True,null=True)
class quick_note_details(models.Model):
meeting_id = models.ForeignKey(quick_note,on_delete = models.CASCADE)
summary = models.TextField(default='',null=True)
Following is the code I have used for saving:
quick_note_details_data = quick_note_details(summary = summary_data,meeting_id = 1)
quick_note_details_data.save()
Using this I am getting following error:
ValueError: Cannot assign "2": "quick_note_details.meeting_id" must be a "quick_note" instance.
Then, I have tried the following approach suggested in the following question,
Django: ValueError when saving an instance to a ForeignKey Field
quick_note_obj = quick_note.objects.get(note_id = note_id)
quick_note_details_data = quick_note_details(summary = summary_data,meeting_id = quick_note_obj)
quick_note_details_data.save()
Using this I am getting following error:
django.db.utils.ProgrammingError: column "meeting_id_id" of relation "website_quick_note_details" does not exist
LINE 1: INSERT INTO "website_quick_note_details" ("meeting_id_id", "...
I don't have a column like meeting_id_id in the model anywhere, then why I am getting this error?
I have been searching for this long time, but didn't get any solution,
Hope I will get help here.
change meeting_id to meeting_id_id , try following
quick_note_details_data = quick_note_details(summary = summary_data,meeting_id_id = 1)
So, I had got my answer days back, so decided to answer so this will help people like me,
Basically, Django appends a suffix to the foreign_key columns,
e.g if your columns name is note ,Django will assume this as note_id,
So,To avoid this I had done only the following:
note_id = models.ForeignKey(quick_note,on_delete = models.CASCADE,db_column='note_id')
By using db_column property, now the foreign key will refer as note_id,
This solves my issue.
I'm trying to manipulate some .sav files with SavReaderWriter. What I already have is this:
with savReaderWriter.SavReader(dirIn, ioUtf8 = True) as reader:
df = pd.DataFrame(reader.all(), columns = [s for s in reader.header])
varLabels = reader.varLabels
varTypes = reader.varTypes
valueLabels = reader.valueLabels
varWidth = reader.varWids # <------------- This guy
varMeasure = reader.measureLevels
varAlignments = reader.alignments
varColumnWidths = reader.columnWidths
varMissingValues = reader.missingValues
and:
with SavWriter(savFileName = dirOut,
varNames = varNames,
varTypes = varTypes,
varLabels= varLabels,
valueLabels = valueLabels,
measureLevels = varMeasure,
columnWidths = varColumnWidths,
alignments = varAlignments,
missingValues = varMissingValues,
ioUtf8=True
) as writer:
for record in records:
writer.writerow(record)
The problem is that I don't know how can I set the Variable Width that I got when reading the sav at fist code, when using the SavWriter part. Does anyone else know what can I do?
I acctually got it working!
First I had to get the formats when reading the .sav:
varFormats = reader.formats
Then just add this param when opening the savWriter:
formats = varFormats
Kind made my way since the docs doesnt help that much, but gave me an idea how the formats works:
https://pythonhosted.org/savReaderWriter/index.html#formats
I don't really understand why this is happening. Maybe a fresh set of eyes could help.
in the table of an access database, say C:\dbase.mdb, I have a table called tProcedureGroups with two fields, ID and Description.
ID Description
1 DIAGNOSTIC
2 PREVENTATIVE
3 RESTORATIVE
So my recordset should be a lot more than an infinite... ID "\t" + Description + "\n"
Here's my code... this had to of happened to a few of you python gurus out there!
Thanks so much for your help, everyone on this site seems super helpful.
import win32com.client
def Procedures(listed):
DB = r"C:\dbase.mdb"
engine = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase(DB)
sql = "select * from [tProcedureGroups]"
access = db.OpenRecordset(sql)
while not access.EOF:
for i in listed:
print i + '\t' + str(access.Fields(i).value) + '\n'
access.MoveNext
fields = ["ID", "Description"]
get_procs = Procedures(fields)
In Python you need to call methods explicitly with ().
So change:
access.MoveNext
to
access.MoveNext()