importing a .txt file into a .dat cplex opl - text

In an optimization problem I need to open my data for the problem in the .dat file. The problem is that the data is in a text file (notebook) and I don't know how I should connect it and work with a lot of instances. Could someone help me? I am searching for it, but I cannot find something that explains clearly.

Open your file in notepad
Go to Save As
Type yourfilename.dat (without space). You should put .dat extension manually
Save

You can read from a text file in cplex like:
execute //you should write this code in an execute block
{
var fileID= new IloOplInputFile("fileName.txt");
var contenct = fileID.readline();
var intContenct = Opl.intValue(contenct); //in case you want to convert what you read into an integer value
fileID.clos();
}

Related

Exporting panda data frame as excel file on FTP

I am exporting a panda data frame as an excel file on FTP and using the below code. The code is creating a file on FTP. The issue here is that if I am make any change in the code and expecting a different output file it is creating the same output file as before. However if I change the file name in: myFTP.storbinary('STOR %s.xlsx' %filename,bio)..It works fine. Moreover, if I made the output on my local keeping the same name it also works fine. I dont want to change the file name every time I make some change in my code."It is not creating a different file with the same name" Below is the code:
myFTP = ftplib.FTP("ftp address","username","password)
myFTP.cwd("change directory/")
buffer=io.BytesIO()
df.to_excel(buffer,index=False)
text = buffer.getvalue()
bio = io.BytesIO(text)
file name = 'FileName_{0}{1}'.format(current_year,current_month)
myFTP.storbinary('STOR %s.xlsx'%file_name,bio)
myFTP.close()
Name of the output file must be: FileName_currentyearcurrentmonth
file name = 'FileName_{0}{1}'.format(current_year,current_month)
If this line of code is as it is in your code, well. It seens you have a syntax error. Also in cases like this contextual manager are actually pretty usefull. Why dont you try doing like this. So if you get an error well you dont keep your file open
with ftplib.FTP("ftp address","username","password) as myFTP:
myFTP.cwd("change directory/")
buffer=io.BytesIO()
df.to_excel(buffer,index=False)
text = buffer.getvalue()
bio = io.BytesIO(text)
file name = 'FileName_{0}{1}'.format(current_year,current_month)
myFTP.storbinary('STOR %s.xlsx'%file_name,bio)

How to open a binary file in my case .nii file using node.js

I want to open a binary file, or at least when I try to open this with the vscode editor, is say that, can't be opened, because is a binary file.
Can someone explain to me what I can do in order to open this type of files and read the content?
About the .nii file format. is a NIFTI1 and used on medical visualization like MRI.
What I trying to do is to read this file at the lowest level and then make some computations.
I will like to use Node.js for this, not any Python or C++.
More details about the file format can be found here.
https://nifti.nimh.nih.gov/
I don't know about how VScode handle binary file but for exemple with Atom (or with another text editor like vi), you can open and view the content of a binary file. This is not very usefull however as the content is not particularly human readable, except maybe some metadata at the top of the file.
$ vim yourniifile.nii
Anyway, it's all depends on what you want to do with that file, which "computation" you're planned to apply to it, and how you will use it after that.
Luckily, there are some npm packages that can help you with the task of reading and processing that kind of file, like nifti-reader-js or nifti-js, for exemple:
const fs = require('fs');
const niftijs = require('nifti-js');
let rawData = fs.readFileSync('yourniifile.nii');
let data = niftijs.parse(rawData);
console.log(data);

Reading an Excel File using BinaryStream reader Without using Microsoft Office DLL

I'm trying to read an excel file from the input Stream.
I want to read line by line and save the column information from Excel to Database.
I'm unable to read the file, Can any one help me to figure out what Im missing.
Here is the code below.
using (System.IO.BinaryReader sr = new System.IO.BinaryReader(fileToUpload.PostedFile.InputStream))
{
do
{
tester.Text = tester.Text + sr.ReadString() + "</br>";
} while (sr.PeekChar() > 0);
}
Thanks
karthik
Normally, in text file, we read line-by-line. I doubt whether Excel also brings data line-by-line (or) you will be able to recognize End-of-line character. If you correlate Excel's row as line, that could be wrong. May be you can try with CSV file, which can be read line-by-line and can be processed as individual lines.

Read data from excel file inside file cabinet

What I want is to read excel file inside netsuite File Cabinet.
On nlapiLoadFile i cant able to read excel file. I used getValue() but result will be in another format.
its show something like dW5kZWZpbm..
How to get data help me out.
finally found the solution..
just to use
var temp = nlapiDecrypt(somestring,'base64');

Upload and Save an excel file with BottlePy

I am creating an application using Bottle framework. I need a feature to upload an Excel file.
I am using the following for file upload.
http://bottlepy.org/docs/dev/tutorial.html#post-form-data-and-file-uploads
On the server side I am getting the file data as binary content. I want to save it in a temporary folder as an Excel file.
I am new to Python and Bottle. Any help will be much appreciated.
Thanks
Chirdeep
Your request.files.data object contains the data about your excel file. So you only need to create a temporary folder and save it inside. This can be done using the tempfile module
f = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
f.write(request.files.data.file.read())
f.close()
I was not able to get simple file writing code like yours to work, So I used the tempfile module. Looking at your code, I would have assumed it would write to the directory where the python file is, if the code is working. Try using the code below, if you don't pass arguments to dir, it will create a file in the current directory.
def save_as_temp_file(data):
with tempfile.NamedTemporaryFile(dir=settings.TEMP_PATH,
delete=False,
suffix=".xlsx") as f:
f.write(data.file.read())
return f.name

Resources